Is there any way of registering a class in jinjava?

203 Views Asked by At

I just started using jinjava. I need to access a list or an array of the next class in the jinjava template:

class Interface {
    public String interfaceName; 
    public String interfaceDesc;  
    public String interfaceIP;
    public String maskbits;
    public Interface(String interfaceName, String interfaceDesc, String interfaceIP, String maskbits) 
    {
        this.interfaceName = interfaceName;
        this.interfaceDesc = interfaceDesc;
        this.interfaceIP = interfaceIP;
        this.maskbits = maskbits;
    }
};

I'm adding the next in the service before rendering the template:

Jinjava jinjava = new Jinjava();

Map<String, Object> context = new HashMap<String, Object>();

Dictionary<String, Object> my_dict = new Hashtable<>();

ArrayList<Interface> interfaces = new ArrayList<Interface>();

interfaces.add(new Interface("eth", "management interface","$*mgmntBR0IpAddress1$","$*mgmntBR0MaskBits1$"));
interfaces.add(new Interface("eth", "pub interface", "$*pubBR1IpAddress1$", "$*pubBR1MaskBits1$"));
interfaces.add(new Interface("eth", "pip interface", "$*pipBR2IpAddress1$", "$*pipBR2MaskBits1$"));
interfaces.add(new Interface("eth", "pip interface", "$*pipBR3IpAddress1$", "$*pipBR3MaskBits1$"));

my_dict.put("interfaces", interfaces);

context.put("my_dict", my_dict);

// reading the template and rendering ...

Then in the template I need to access each element in the list of interfaces:

{% for interface in my_dict.interfaces %} 
    clish -s -c "set interface {{interface.interfaceName}}{{loop.index}} state on"
{% endfor %}

But the rendered template is showing empty spaces where {{interface.interfaceName}}.

I'm I missing something? Thanks in advance for the help

0

There are 0 best solutions below