I've been working on my first EE plugin today, and I need to make it dynamic by passing either a PHP variable, or I would have thought I can use a preload_replace variable, from the template that calls the plugin, into the plugin.

The plugin runs a custom query on the database to return a set of entry IDs into the channel entries tag. But I need to set a category ID in the the template that would be dynamic depending on the template been viewed. This needs to be passed into the plugin for the query to run.

How can I pass this in?

I've tried numerous ways with the template class, and using PHP by setting a variable in the template, but no success. I just keep getting an undefined variable error.

Can anyone offer any pointers, please?

  • Can you post the code you're using to set your preload_replace variable? What determines whether a category should be set - a segment? Sep 4, 2013 at 15:56

1 Answer 1


I've found a way to do this; not sure its the 'right' way, but it works and seems logical :-)

{exp:plugin_name parse="inward" variable_to_pass="{some_id}"}

Then in the plugin:

$my_var = $this->EE->TMPL->fetch_param('some_id');
  • That is exactly how to do this. Sep 4, 2013 at 17:01
  • Since you named your parameter in this example variable_to_pass you should use that same name in the fetch_param argument. Like $this->EE->TMPL->fetch_param('variable_to_pass');
    – Alex Kendrick
    Sep 4, 2013 at 19:35

Your Answer

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

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