在模板调用中引用变量 - 明亮

时间:2016-10-26 20:25:49

标签: sightly htl

我正在尝试在data-sly-template调用中调用引号内的变量。我希望输出包含我的字符串与适当的变量内部引号。下面是模板和我用来调用它的字符串:

模板:

    <!-- template -->
    <template data-sly-template.bnrButton="${ @ style='String: button color class (default btn-primary)', classes='String: additional component button classes', text='String: button text (translation key)', defaultText='String: default button text (translation key)', link='String: link target for button (# is default)', fullWidth='Boolean: whether to display button in full width of container', noFollow='Boolean: if button should have a nofollow tag (no is def)', gaCategory='String: GA Category', gaEvent='String: GA Event', gaLabel='String: GA Label', gaAction='String: GA Action'}">
    <a class="btn ${style || 'btn-primary'} hidden-print ${classes}${fullWidth ? ' btn-full-width' : ''}" role="button" href="${link || '#'}" rel="${noFollow ? 'nofollow' : ''}" onclick="${gaEvent @ context = 'scriptString'}">${text || defaultText  @ i18n}</a>    
    </template> 

    <!-- call made to the template -->
    <sly data-sly-call="${patterns.bnrButton @ style='btn-secondary-light', classes='btn-sm', text=teaser.libraryButtonHeading, defaultText='View Library', link=teaser.myLibraryLink.href, fullWidth='true', newWindow='false', gaEvent='trackEvent(&#39;Test 1&#39;,&#39;Test 2&#39;,&#39;${teaser.teaserMessage}&#39;)'}"></sly>

如果尝试了多种组合来获取teaser.teaserMessage来打印创作的消息,但由于模式调用已在引号内,因此一直存在问题。我希望能够将单个字符串(在模板调用中调用)传递给模板,该模板包含onclick所需的所有信息。

思想?

谢谢。

1 个答案:

答案 0 :(得分:0)

您可以在模板调用之前使用data-sly-test.variable_name将值存储到变量中:

<sly data-sly-test.gaEvent="${'trackEvent(&#39;Test 1&#39;,&#39;Test 2&#39;,&#39;{0}&#39;)' @ format=teaser.teaserMessage}"
     data-sly-call="${patterns.bnrButton @ ..., gaEvent=gaEvent }"></sly>