I’m having an issue with a plugin where I’m passing a variable value (rich text string) into the plugin like this:
{exp:char_count:pair value="{presentations__details}" compare="800"}
The value of {presentations__details}
contains some quote marks, which seems to result in the value being passed into the parameter getting cut off. As you might imagine, this is frustrating. I suppose that, because of the way templating works, the variable value is being expanded before the plugin runs and the quote mark being a delimiter, as soon as it hits the first quote in the variable value, it ends the value set. Since the value could also contain single quotes, switching the params to single quotes won’t really work.
Any ideas?
So what I ended up doing was creating a set method that storage values:
{exp:char_count:set key="presentations"}
{presentations__details}
{/exp:char_count:set}
And then telling my plugin what key to use to retrieve the data.
{exp:char_count:pair value_key="presentations" compare="800"}
Not the most ideal, but it will do to be getting on with. In an ideal world, it would be possible to pass variables into plugins.
Yep in this case Kevin’s spot on, tag data is the way to go instead of a tag parameter. Similar to HTML where you can’t use unknown input as a tag attribute without escaping or handling special characters, so you cannot pass unknown user input into an ExpressionEngine tag without escaping or special handling. There are plugins that can do this for you, but since your goal is capture and not output, tagdata is the best way.
That said, I’m confused on why you’re having to use two sets of tags to accomplish this. From your original post’s code, I’d expect you to be able to do the following:
{exp:char_count:pair compare="800"}{presentation_details}{/exp:char_count:pair}
And in your plugin instead of $value = ee()->TMPL->fetch_param('value');
, just use $value = trim(ee()->TMPL->tagdata);
.
That said, I’m confused on why you’re having to use two sets of tags to accomplish this.
When I’m at my computer next I’ll try to remember to provide more context. Basically, I have a tag pair that provides several variables, count, over provided amount, equal to provided amount, under provided amount, etc. and I’m doing various things based on those variables within the tag pair. So I want to provide variables to check against based on the provided count once and have those available throughout the tag pair. I hope that makes sense on my phone.
I’m the site builder 😉
I’ve cut out a lot to make this more readable here, but this is the gist of it. This is working fine, I just wish I could pass variables straight to my tag pair.
{exp:channel:entries stuff}
{exp:char_count:set key="presentations"}
{presentations__details}
{/exp:char_count:set}
{exp:char_count:pair value_key="presentations" compare="800"}
<div class="layer-agenda__line{if char_count:gt} js-read-more{if:else} layer-agenda__line--is-always-expanded{/if}" >
<div class="layer-agenda__line-inner{if char_count:gt} js-read-more__inner{/if}">
<div class="layer-agenda__line-left">
<div class="layer-agenda__time">
{entry_date timezone="America/Denver" format="%g:%i %A"} – {expiration_date timezone="America/Denver" format="%g:%i %A"}
</div>
</div>
<div class="layer-agenda__line-right">
<div class="layer-agenda__session-details">
{exp:low_widont}{exp:typographee:parse}{presentations__details}{/exp:typographee:parse}{/exp:low_widont}
</div>
{if char_count:gt}
<span class="layer-agenda__read-more js-read-more__activator">
<span class="layer-agenda__read-more-text">
Read More
</span>
<span class="layer-agenda__read-more-caret"></span>
</span>
<span class="layer-agenda__read-less js-read-more__activator">
<span class="layer-agenda__read-less-text">
Read Less
</span>
<span class="layer-agenda__read-less-caret"></span>
</span>
{/if}
</div>
</div>
</div>
{/exp:char_count:pair}
{/exp:channel:entries}
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.