I have a rendering macro and a jsx for behavior on the client. How to make it so that jsx works only on the parts that were rendered by the respective rendering macro?
So, let’s say I have this rendering macro HelloWorld:
And it has a parameter makeTextBold. The jsx should either make the text bold or not.
Then on some page I enter the macro twice:
{{HelloWorld makeTextBold=false /}}
{{HelloWorld makeTextBold=true/}}
How to make jsx determine which paragraph to make bold and which not to make? I can generate a random number and set it as an id of an element, and it’ll work but it feels hacky.
That was just an example. Yes, in this case I can do it in the backend, but in real situation I am working on an editor for objects and I’d like to support multiple editors for the same type of objects on the same page. But how do I tell jsx which html element to use?
Once I put two:{{ObjectEditor /}} macro, how to make jsx only work on their appropriate html?
I searched and found the UIN Script Service but it’s persistent between server restarts, and I need to uniquely identify html elements only for the page. I guess, some other unique identifier component could be written that would only be persistent on the same page, but I don’t understand how to do that either: service that would generate unique ids for the same request.
Make it possible to have multiple macros{{Editor /}} on the same page, and let jsx to only work on their respective parts.
And I solved it by giving an id to the element and saving it in the xcontext variable, so the ids don’t repeat between macro calls, allowing for multiple editors on the same page:
As the scripts (velocity, groovy, php, …) share the binding you can declare global variables which can be accessed (read/write) by a script call sequence (even in different languages):
e.g:
{{groovy}}
if (binding.hasVariable("myCounter" )) {myCounter+=1} else {myCounter=1}
{{/groovy}}
You can avoid numbering, if you use the javascript function parentNode iteratively to find the beginning of the html code generated by your macros and characterized with a class name.