Conditional nodes under grouping

Hello Experts,

I have grouping with certain containers. e.g

Grouping grpA {

Container A {
//visible only if using parent is X;
}
Container B {
//visible only if using parent is Y;
}
Container C {
//visible only if using parent is Z;
}
Etc …,

}
Im thinking just to use like below

Grouping grpA {

Container A {
When “…/X”;
}

etc …,
}

You can use when-clauses inside of a grouping. Just be aware that if the grouping is used in several places in your model, you may need to full paths instead of relative paths.

While this should indeed be possible, it is probably not a good idea. Whenever you write a YANG module, you should have this quote from https://tools.ietf.org/html/rfc7950#section-6 in mind:

   [...] YANG values the time and effort of the
   readers of models above those of modules writers and YANG tool-chain
   developers.

A well-defined grouping, e.g. containing a set of parameters that are familiar to most readers, can be a great help in saving “time and effort” for the readers - it reduces clutter and makes it easier to get “the big picture” of the module. On the other hand, if the grouping just contains some more or less random statements that happen to appear in multiple places, and primarily exists to save a bit of typing for the module writer, the effect is the opposite - the reader has to interrupt the flow of reading and go and check the grouping contents whenever there is a uses statement for it.

A grouping whose contents effectively depend on where it is used is even more problematic - it is not enough to check the contents of the grouping, the reader must go back and check the context of the uses statement to see what the actual contents will be in the current case.

A good test is to see if you can come up with a short and descriptive name for the grouping.