On Sunday 11 September 2016 21:19:23 Adam Henderson wrote: > Hi, Hello Adam,
> Being relatively new to Sling, is there an OOTB way to allow special tokens > to be inserted into the textual content (not into sly/jsp templates) that > when rendered can be resolved to some value (e.g. invoking a method on a > service or a reference to a property in the JCR). > > eg: > > /apps/pages/productdetails.html > > /content/page/product1details > - sling:resourceType: pages/productdetails > > /content/products/product1 > - description : string = “This is the description of Product 1, hurry - > discount of $JCR[‘/content/promotions/discounts:holidayspecialdiscount’]% > applies!” > > /content/promotions/discounts > - holidayspecialdiscount : double = 10 > > So I would like Sling to resolve the $JCR token so that what is shown to the > user would be: > > "This is the description of Product 1, hurry - discount of 10% applies!" > > So how would you approach this in in a Sling environment. there are several ways to do it in Sling and it really depends on your requirements. Post-processing: use Sling Rewriter or SSI to replace/fill the token/variable after the page resource was processed by your scripting engine. Sling Models: use a Sling Model in your script and let it do the string processing. Scripting engine: extend your scripting engine with a special tag/processor which will do the string processing. You will need some kind of service to pick up the value by query from the repo in any way. Regards, O. > Many thanks, > Adam.
