How to set convenience variables in sightly?

Avatar

Avatar

paro22

Avatar

paro22

paro22

15-10-2015

Hey all,

is there a way to set variables in sightly? Basically I have a lot of variables in my html template and it's getting kind of messy, especially with things like inherited properties [1] and combination of properties for conditions [2]. In a jsp I could just use <c:set> but not here. Any suggestions?

Thanks!

Paul

[1] example for long properties: ${inheritedPageProperties['parBloc1/topbanner/narrow']}

[2] data-sly-test="${inheritedPageProperties['parBloc1/topbanner/narrow'] && inheritedPageProperties['parBloc1/topbanner/test']}"

desktop_exl_promo_600x100_weknowyou.png

View Entire Topic

Avatar

Avatar

gabriel_walt

Employee

Avatar

gabriel_walt

Employee

gabriel_walt
Employee

15-10-2015

His code example is doing exactly that, it sets yourName in the test, which can then be reused within or later on:

<div data-sly-test.yourName="${currentPage.name}">....${yourName}</div>

Have a quick look at the docs of data-sly-test to better understand that behavior.

More generally though, if you need to set many variables in your template, I'd rather advise you to use the Use-API to prepare all the variables you'll need in your template. This will probably be easier to understand by someone reading your template and thus be more maintainable than setting variables in your template.