0

I'm trying to make a plugin that I need to be as simple as possible to use. If possible, I want the usage to be:

{exp:pluginname:anytext}

And the output to be:

anytext

Obviously there will be more to it than just that, but the essence is that I need the "anytext" bit to be any bit of text, not a hard-coded method.

I've seen plugins that make use of the 4th tagpart, eg. {exp:ce_img:make:anytext ... }, where the anytext bit gets used as a variable prefix. Unfortunately, when I try to do something similar, but using the 3rd tagpart instead, I get an error:

Error

The following tag cannot be processed:

{exp:pluginname:anytext}

Please check that the ‘pluginname’ module is installed
and that ‘anytext’ is an available method of the module
1

Why are you trying to go about it like that? If you need to make the plugin as simple as possible, the Tag Pair syntax is far easier than trying to understand why you want a text input as a segment of the tag:

{exp:my_plugin}
    anytext
{/exp:my_plugin}

EE Plugin parsing library always looks for a method in your plugin class if you have a second tag part. So you can't do it your way, however, if you want to use four segments like CE Image:

$tag_parts = $this->EE->TMPL->tagparts;

In an example:

// {exp:my_plugin:anytext:stuff}

$tag_parts = ee()->TMPL->tagparts; 

$tag_parts[0] = "my_plugin";
$tag_parts[1] = "anytext"; // ALWAYS evaluated as a plugin_name::anytext()
$tag_parts[2] = "stuff";
| improve this answer | |
  • I'm actually trying to make it work with as little typing as possible; it doesn't need to be simple in the sense of easy-to-understand. It's basically going to be a shortcut to using a whole bunch of difficult-to-remember HTML, where you only need to supply one variable. So, {exp:plugin:foo}, {exp:plugin:bar}, etc would have been ideal. I guess I could settle for {exp:plugin:verb:foo}, but it just seems extraneous at the moment. Perhaps I'll figure out another use for the plugin that would cover {exp:plugin:verb2}, giving both a reason to exist separately. Thanks, J! – Sandwich Sep 25 '15 at 17:07
  • If it really is for dropping in difficult-to-remember HTML, I can't see a single advantage for this over just using EE native snippets. – jrothafer Sep 25 '15 at 17:10
  • Can't pass a variable to a snippet unless you use preload_replace, and that's already typing a lot more than I want... I don't assume there's a way to omit the exp portion, is there? I know Stash does it in certain circumstances, but I suspect there's some trickery involved. – Sandwich Sep 25 '15 at 17:10
  • Here's the published plugin - something to help out with SVG icons from an external file. I hope now it makes sense why I wanted things as brief as possible. :) I also ended up adding a tag pair mode thanks to you, which should make integration with data from channel entries easier. :) – Sandwich Sep 27 '15 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.