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

Sending value to plugin

How Do I?

NutsAndBolts's avatar
NutsAndBolts
2 posts
8 years ago
NutsAndBolts's avatar NutsAndBolts

So I have a simple plug-in that needs to make some string adjustments before displaying in the template, but already stumped on something:

The channel entry has a field that has a text input such as: “Men’s Clothes” When I send this to the plugin, I get “Men”, since I’m guessing the apostrophe isn’t allowing the entire string to go through.

So the question is: how do I get the entire string to go through?

In the plugin (partial display):

public function display() {
        $stringy_val = $this->EE->TMPL->fetch_param("var");
//...do string changes to variable
return $stringy_val;

In the template:

{exp:channel:entries channel="clothes" dynamic="no"}
{exp:stringyadj:display var='{clothing_line}'}
{/exp:channel:entries}

And clothing_line having value: Men’s Clothes

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

For plugins that perform string formatting on content, it’s best to use them as tag pairs. This allows it to suck up all of the content without you having to worry about whether or not the input would break a single or double-quoted parameter (much like you have to do for HTML attributes).

{exp:channel:entries channel="clothes" dynamic="no"}
    {exp:stringyadj:display}{clothing_line}{/exp:stringyadj:display}
{/exp:channel:entries}

In your plugin, this content is available via ee()->TMPL->tagdata. You can operate on it directly, or copy it to a string. You’ll still return your processed string in the same way, it just won’t be coming from a tag parameter.

For more information, see Plugins:// processing data within tag pairs

       

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.