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
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
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.