cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
921
Views
5
Helpful
2
Replies

Get the leafref value in the template

hello dears how could I Pass the values of my leafref in my template without passing them with python variable.

for example if I have a service called child:

....
leaf id{
type string;
}
leaf name{
type string;
}
leaf birth{
type string;
}
...

and other service called parent that ref to the child service :

....
leaf id{
type string;
}
leaf name{
type string;
}
leaf child{
type leafref{
 path "/c:child/c:id";
}
...

In the template file of the service parent I'd like to pass the child values even the id and both name and birth.

I now this could be use by python but in my case it will require a big refactor of my services.

Your advices wil appreciate.

 

regards.

2 Replies 2

snovello
Cisco Employee
Cisco Employee

Hello,

 

I think the most convenient way to do that in your template is to use the deref() function.

 

So in the parent service templates you will use a xpath like {deref(child)/../birth}.

 

deref() is moving your xpath context to the leaf that your leafref points to. Then you practically always use /../ to go up to the parent of the leaf, and then you navigate from there.

Great it work!!!! many Thx.