Skip to content

Instantly share code, notes, and snippets.

@gabrielwalt
Last active June 12, 2017 15:12
Show Gist options
  • Save gabrielwalt/02a52025c33f9d87fdb0b6ca8b90ea0e to your computer and use it in GitHub Desktop.
Save gabrielwalt/02a52025c33f9d87fdb0b6ca8b90ea0e to your computer and use it in GitHub Desktop.
Pass markup to a template
<sly data-sly-template.card="${@ img, title, content}">
<div class="card">
<img src="${img}" alt/>
<h2>${title}</h2>
<div class="content" data-sly-test="${content}" data-sly-call="${content}"></div>
</div>
</sly>
<sly data-sly-template.example>
<p>This example shows how to pass markup to a template</p>
</sly>
<sly data-sly-call="${card @ img='hello.jpg', title='Hello World', content=example}"></sly>
<div class="card">
<img src="hello.jpg" alt/>
<h2>Hello World</h2>
<div class="content">
<p>This example shows how to pass markup to a template</p>
</div>
</div>
@gabrielwalt
Copy link
Author

@jantimon, You can do that, but just need to move your inner data-sly-template outside as they cannot be nested. When doing that however, you'll notice that your example will infinitely recourse.

I guess that what you rather wanted to do is something like that:

<sly data-sly-template.innerContent>Demo</sly>

<sly data-sly-template.innerCard>
    <sly data-sly-call="${card @ img='hello.jpg', title='Inner Card', content=innerContent}"></sly>
</sly>

<sly data-sly-call="${card @ img='hello.jpg', title='Outer Card', content=innerCard}"></sly>

And if needed, the parameters could also be passed along from the card to the content template, because in that example the inner card is mostly hardcoded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment