Passing Concatenated Strings to Sightly Template | Community
Skip to main content
New Participant
June 27, 2017
Solved

Passing Concatenated Strings to Sightly Template

  • June 27, 2017
  • 2 replies
  • 5859 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by ohara239

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

2 replies

ohara239
ohara239Accepted solution
New Participant
June 27, 2017

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

smacdonald2008
New Participant
June 27, 2017

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.