Reputation: 2989
I got this template:
{?doesExtend}
{>base_template/}
{<param}
<div id='abc'>{foo}</div>
<div id='def'>{bar}</div>
<div id='ghi'>{bas}</div>
{/param}
{:else}
<div id='abc'>{foo}</div>
<div id='def'>{bar}</div>
<div id='ghi'>{bas}</div>
{/doesExtend}
This works but it's not DRY...I have to put the HTML in twice. How can I make it so that if doesExtend exists, then it will extend the template to a base template, and if it doesn't exist, then it will simply not extend it and render it as is, in a way that is DRY?
Upvotes: 0
Views: 76
Reputation: 5609
I would just move the repeated code into a separate partial.
{! "div_template" !}
<div id='abc'>{foo}</div>
<div id='def'>{bar}</div>
<div id='ghi'>{bas}</div>
Then your original template would look like:
{?doesExtend}
{>base_template/}
{<param}
{>div_template/}
{/param}
{:else}
{>div_template/}
{/doesExtend}
Upvotes: 1