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.

  • 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)? – Peter Lewis Jul 4 '14 at 9:51
  • Sorry, in the implementation of the plugin (pi.foo.php), I want to access the output of a template. – ExpressionEngineNewbie Jul 4 '14 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. – Peter Lewis Jul 4 '14 at 14:08
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.

| improve this answer | |
  • 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. – ExpressionEngineNewbie Jul 4 '14 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. – Jan Henckens Jul 7 '14 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.

| improve this answer | |

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.