How do I concatenate strings in Sightly / HTL?

I have the following code:

<sly data-sly-use.link="${'core.impl.view.tools.LinkUtils' @ path=properties.targetURL}"></sly>

      

I want to merge properties.linkType

into properties.targetURL

.

Any ideas how this can be done? I found examples on the net but they don't seem to work for my use.

+3


source to share


2 answers


It depends on what combination of lines you mean:



  • String concatenation using the operator is not supported , i.e. you cannot do . A workaround (suggested by @Jens) is to do something like: ${properties.targetURL + properties.linkType}

    <sly data-sly-test.concatenated="${'{0}{1}' @ format=[properties.targetURL, properties.linkType]}"></sly>

  • Concatenating strings into HTML output can be done by placing the HTL expression next to each other, i.e. ${properties.targetUrl}${properties.linkType}

  • Sending both strings to a use object is supported by several expressions: <sly data-sly-use.link="${'core.impl.view.tools.LinkUtils' @ path=properties.targetURL, type=properties.linkType}"></sly>

  • Concatenating strings to form a URL may be possible in some cases using URI Manipulation
+6


source


I just want to add another way to concatenate strings in the above answer using @ join

.

<sly data-sly-test="${['String1','String2','String3'] @ join = '-'}"/>

      



It will give output like:   String1-String2-String3

+2


source







All Articles