0

From within a plugin, is it possible to access a template? I need to do some processing on the resulting output of a template from within the plugin.

3
  • Need more information. Do you mean anywhere in the template, or if your plugin is a tag pair, getting the contents of the tag pair as @Jannemans describes. Your comment hints at the plugin "reading" the template directly, not necessarily where the plugin is used. Is it actually a template you want or an external view file (as in a Module)? Jul 4, 2014 at 9:51
  • Sorry, in the implementation of the plugin (pi.foo.php), I want to access the output of a template. Jul 4, 2014 at 11:25
  • "output of a template" - the template the plugin is used in and being rendered to screen? Another template in the system? The whole template not just content within your tag pair? Template unparsed? Template parsed? Are you intending to parse it and output it within the plugin? If so, what EE code is in the template (other add-ons, fieldtypes used, tags used, etc)? The more information you provide to help clarify the easier it is to help. Jul 4, 2014 at 14:08

2 Answers 2

1

Using ee()->TMPL->tagdata you have access to every element between your plugin tags on the page. You can then do anything with that and return it to the page using ee()->TMPL->parse_variables

I'd suggest checking out the Template Class docs for more details.

2
  • Does this mimic an "embed?" The template I'm trying to "embed" from within the template outputs a JSON. I want to do some post-processing to that JSON from within the template. Jul 4, 2014 at 9:19
  • Not really like embed, the Template class allows you to define your own tag or tag pair, get data from within that tag(pair), do something with that data and return the result to that same template. Jul 7, 2014 at 8:41
0

You could also have your plugin take a parameter json="json data" and then you would have it to parse and render in your plugin then display it back in your template.

Template:

{exp:jsonplugin json="{embed="your/template}"}

Plugin:

$json = ee()->TMPL->fetch_param('json');

In your plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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