I'm using an if statement in a layout to check if a layout variable contains any content.
{if layout:sidebar}
<div class="sidebar">
{layout:sidebar}
</div>
{/if}
This works well if {layout:sidebar}
hasn't been set at all by the template that is using this layout, but sometimes {layout:sidebar}
will have spaces or newline characters in it, but nothing else (because contents get set conditionally in the templates that use this layout).
Things I've tried:
{!-- Will display the sidebar if there are newlines/spaces in layout:sidebar --}
{if layout:sidebar}
<div class="sidebar">
{layout:sidebar}
</div>
{/if}
{!-- Same result as above...which makes sense --}
{if layout:sidebar != ''}
<div class="sidebar">
{layout:sidebar}
</div>
{/if}
{!-- Will never display the sidebar --}
{if {exp:streeng trim="both"}{layout:sidebar}{/exp:streeng} != ''}
<div class="sidebar">
{layout:sidebar}
</div>
{/if}
{!-- Will never display the sidebar --}
{if {exp:streeng find='SPACE|NEWLINE' trim='' }{layout:sidebar}{/exp:streeng} != ''}
<div class="sidebar">
{layout:sidebar}
</div>
{/if}
{!-- Breaks if {layout:sidebar} contains a double quote --}
{if "{exp:streeng find='SPACE|NEWLINE' trim='' }{layout:sidebar}{/exp:streeng}" != ''}
<div class="sidebar">
{layout:sidebar}
</div>
{/if}
{!-- Breaks if {layout:sidebar} contains a single quote --}
{if '{exp:streeng find='SPACE|NEWLINE' trim='' }{layout:sidebar}{/exp:streeng}' != ''}
<div class="sidebar">
{layout:sidebar}
</div>
{/if}
Other than combing through templates that use this layout and set layout:sidebar
and removing any newlines or spaces, what is the best way to conditionally include or exclude the sidebar in this scenario?
parse='inward'
to the if statement