We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Passing variable value to plugin where variable value has quote mark

Developer Preview

TJ Draper's avatar
TJ Draper
222 posts
7 years ago
TJ Draper's avatar TJ Draper

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?

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
7 years ago
Kevin Cupp's avatar Kevin Cupp

Can you pass the variable in as tag data instead of a parameter?

       
TJ Draper's avatar
TJ Draper
222 posts
7 years ago
TJ Draper's avatar TJ Draper

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.

       
Derek Jones's avatar
Derek Jones
7,561 posts
7 years ago
Derek Jones's avatar Derek Jones

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);.

       
TJ Draper's avatar
TJ Draper
222 posts
7 years ago
TJ Draper's avatar TJ Draper

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.

       
Derek Jones's avatar
Derek Jones
7,561 posts
7 years ago
Derek Jones's avatar Derek Jones

Ok, so your original example would have had a closing tag, and the plugin has its own variables? If you can provide a complete tag sample I might be able to make some suggestions to keep it as simple as possible for both you and the site builder.

       
TJ Draper's avatar
TJ Draper
222 posts
7 years ago
TJ Draper's avatar TJ Draper

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"} &ndash; {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}
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.