The api and bindings

Is there any way to set the template bindings in an extension?

I tried using IPSAssemblyItem.getBindings(), but this didn’t seem to effect the bindings in the template. IPSAssemblyTemplate has a getBindings() method, but that requires that I have an IPSTemplateBinding object, for which there is no class exposed in the API (Would it work to create my own IPSTemplateBinding class… or is this even the right path?)

What I’m trying to do is have an extension that will set some variables that our templates use a lot.

For now, I’m going to just return a hash and set it explicitly in the bindings. I guess that would work pretty well.

Thanks

IPSAssemblyItems.setBindings(Map<String,Object>) should do what you want.

You can create a JEXL function that takes $sys.assemblyItem as a parameter and then call this method to set/reset the bindings.

If that’s not what you are trying to do, then perhaps I don’t understand the question.

Dave

PS: getBindings() returns a read-only copy of the bindings map. You cannot use it to modify the map.

I could swear that I tried that. My JEXL method does take $sys.assemblyItem. At first, I just tried getBindings and updated the hashmap. When that didn’t work, I tried calling setBindings.

But maybe I’ll try it again.