Expand my Community achievements bar.

SOLVED

Passing Concatenated Strings to Sightly Template

Avatar

Level 5

I have a template called "passTitle" that applies some special formatting to a title element that is used dozens of times in a script. Here's the header for that title:

<template data-sly-template.passTitle="${@title, type}">...</template>

Usually, the title is one string, but sometimes it's multiple things that need to be concatenated. I can't figure out how to get this to work.

Here's the basic call without concatenation, which works fine:

<sly data-sly-call="${passTitle @ title='Title', type='h3'}" />

Here are some of my  attempts at a concatenation:

<sly data-sly-test="${showTitle}" data-sly-call="${passTitle @ title=('What is {0}' @format=[data.BaseInfo.ProgramTitle]), type='h3'}" />

<sly data-sly-test="${showTitle}" data-sly-call="${passTitle @ title='What is {0}' @format=[data.BaseInfo.ProgramTitle], type='h3'}" />

<sly data-sly-test="${showTitle}" data-sly-call="${passTitle @ title='What is ' + data.BaseInfo.ProgramTitle}, type='h3'}" />

<sly data-sly-test="${showTitle}" data-sly-call="${passTitle @ title=['What is ', data.BaseInfo.ProgramTitle] @ join='', type='h3'}" />

These give me various errors. My best bet was probably the {0} templating, but that doesn't seem to be supported to the right of '@'

Am I out of luck here?

I know I can do this with a pretty simple js use class, but I'd prefer not to.

1 Accepted Solution

Avatar

Correct answer by
Level 2

There is a thread on Stack Overflow that gives a great answer and helps to explain why you will end up back at smacdonald2008​'s answer.


Evaluating expression and pass as argument in Sightly AEM - Stack Overflow

View solution in original post

2 Replies

Avatar

Level 10

Use JS or Java - HTL syntax is more of a view - it does basic operations (like looping and conditions), but for more complex operations - use JS or Java.

Avatar

Correct answer by
Level 2

There is a thread on Stack Overflow that gives a great answer and helps to explain why you will end up back at smacdonald2008​'s answer.


Evaluating expression and pass as argument in Sightly AEM - Stack Overflow