如何连接Sightly / HTL中的字符串?(How to concatenate strings in Sightly/HTL?)

编程入门 行业动态 更新时间:2024-10-27 22:33:39
如何连接Sightly / HTL中的字符串?(How to concatenate strings in Sightly/HTL?)

我有以下代码:

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

我想将properties.linkType连接到properties.targetURL 。

任何想法如何做到? 我在网上找到了一些例子,但它们似乎不适合我的用例。

I have the following code:

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

I want to concatenate properties.linkType to properties.targetURL.

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

最满意答案

这取决于你想要什么样的字符串连接:

不支持使用运算符连接字符串,即。 你不能做 ${properties.targetURL + properties.linkType} 。 解决方法(由@Jens建议)是做如下工作: <sly data-sly-test.concatenated="${'{0}{1}' @ format=[properties.targetURL, properties.linkType]}"></sly> 在HTML输出中连接字符串可以通过将HTL表达式放在一起来完成,即。 ${properties.targetUrl}${properties.linkType} 通过多个表达式选项支持将这两个字符串发送到使用对象: <sly data-sly-use.link="${'core.impl.view.tools.LinkUtils' @ path=properties.targetURL, type=properties.linkType}"></sly> 在一些使用URI操纵的情况下,连接字符串以形成URL可能是可能的

That depends on what kind of string concatenation you have in mind:

Concatenating strings using an operator is not supported, ie. you cannot do ${properties.targetURL + properties.linkType} . A workaround (suggested by @Jens) is to do something like: <sly data-sly-test.concatenated="${'{0}{1}' @ format=[properties.targetURL, properties.linkType]}"></sly> Concatenating strings in HTML output can be done by placing HTL expression next to each other, ie. ${properties.targetUrl}${properties.linkType} Sending both strings to an Use Object is supported via multiple expression options: <sly data-sly-use.link="${'core.impl.view.tools.LinkUtils' @ path=properties.targetURL, type=properties.linkType}"></sly> Concatenating strings to form an URL might be possible in some cases using URI Manipulation

更多推荐

本文发布于:2023-07-05 14:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1038435.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   HTL   Sightly   concatenate   strings

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!