I have a use case where I need to set a maxChars
variable to pass into the Wordsmith plugin’s chop
parameters.
So I know I can do this (with the Empty Coalesce plugin):
{% set maxChars = matrixBlock.maxChars ??? null %}
{% set intro = entry.intro ??? null %}
{% if intro and maxChars %}
{% set intro = intro|md|chop(limit= maxChars, unit='c', allowedTags='<p><em><strong><a>') %}
{% endif %}
…
<div class="whatever">
{{ intro|raw }}
</div>
But maxChars
might be null
and I might want the allowedTags
string to be a variable too, so it would be handy to be able to set the chop parameters as a hash and pass them in.
The following doesn’t seem to work, but is there something that does?
{# Default tags permitted #}
{% set chopArgs = { allowedTags: '<p>' } %}
{# Custom tag list #}
{% set tagList = matrixBlock.tagList ??? null %}
{% if maxChars %}
{% set chopArgs = chopArgs|merge({ limit: maxChars, unit: 'c' }) %}
{% endif %}
{% if tagList %}
{% set chopArgs = chopArgs|merge({ allowedTags: tagList }) %}
{% endif %}
…
{% if intro %}
{% set intro = intro|md|chop(chopArgs) %}
{% endif %}