Answers.Body: <p>Your only problem here is <code>limit</code> but would something like this work for you?</p>
  <pre><code>{# Default tags permitted #}
  {% set defaultTags = &quot;&lt;p&gt;&quot; %}
  
  {# Concatenate default + custom tags #}
  {% set allowedTags = defaultTags ~ matrixBlock.tagList ?? null %}
  
  {# Limit - use if provided or set to unlimited using a huge number #}
  {% set limit = matrixBlock.maxChars ?? 1000000000000000 %}
  
  {% if intro %}
      {% set intro = intro|md|chop(limit= limit, unit='c', allowedTags=allowedTags) %}
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-29T11:28:40.653Z
Answers.Text: You’re right. Thanks Oli
Answers.UserDisplayName: Jonathan Schofield
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-27T09:47:38.780Z
Answers.LastActivityDate: 2020-11-27T09:47:38.780Z
Answers.UserDisplayName: Oli
Body: <p>I have a use case where I need to set a <code>maxChars</code> variable to pass into the Wordsmith plugin’s <code>chop</code> parameters.</p>
  <p>So I know I can do this (with the <a href="https://plugins.craftcms.com/empty-coalesce" rel="nofollow noreferrer">Empty Coalesce plugin</a>):</p>
  <pre><code>{% set maxChars = matrixBlock.maxChars ??? null %}
  {% set intro    = entry.intro ??? null %}
  
  {% if intro and maxChars %}
      {% set intro = intro|md|chop(limit= maxChars, unit='c', allowedTags='&lt;p&gt;&lt;em&gt;&lt;strong&gt;&lt;a&gt;') %}
  {% endif %}
  
  …
  
  &lt;div class=&quot;whatever&quot;&gt;
      {{ intro|raw }}
  &lt;/div&gt;
  </code></pre>
  <p>But <code>maxChars</code> might be <code>null</code> and I might want the <code>allowedTags</code> 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.</p>
  <p>The following doesn’t seem to work, but is there something that does?</p>
  <pre><code>{# Default tags permitted #}
  {% set chopArgs = { allowedTags: '&lt;p&gt;' } %}
  
  {# 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 %}
  </code></pre>
  
Tags: <plugins><params>
Title: How to pass dynamic arguments into Wordsmith chop parameters?
ThreadText: # How to pass dynamic arguments into Wordsmith chop parameters?
  
  (Asked by: username_0 on 2020-11-26)
  
  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](https://plugins.craftcms.com/empty-coalesce)):
  
  ```
  {% 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 %}
  
  ```
  
  **Tags:** plugins, params
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-11-27. Score: 2
  
  Your only problem here is `limit` but would something like this work for you?
  
  ```
  {# Default tags permitted #}
  {% set defaultTags = "<p>" %}
  
  {# Concatenate default + custom tags #}
  {% set allowedTags = defaultTags ~ matrixBlock.tagList ?? null %}
  
  {# Limit - use if provided or set to unlimited using a huge number #}
  {% set limit = matrixBlock.maxChars ?? 1000000000000000 %}
  
  {% if intro %}
      {% set intro = intro|md|chop(limit= limit, unit='c', allowedTags=allowedTags) %}
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: You’re right. Thanks Oli  
  
  ---
  
  