We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Tag sent as plugin parameter not evaluated

Development and Programming

ElephantMan's avatar
ElephantMan
3 posts
15 years ago
ElephantMan's avatar ElephantMan

I’m writing my first plugin (EE 2.1) and it accepts a single parameter that is supposed to be the current member_id. However, when I do <ext:my_plugin:my_func my_param=”{member_id}”> I literally get the string “{member_id}” and not the numeric value from $this->EE->TMPL->fetch_param(‘my_param’). I also tried using an open/close tag, but I get the same behavior from $this->EE->TMPL->tagdata. I’ve tried eliminating quotes around the tag and using single quotes. {member_id} does evaluate correctly when used in the template proper.

Do I have to do something special to tell EE to evaluate tags passed as parameters to a plugin? The plugin docs do it all over the place and seem to imply that it should work fine.

Thanks for any help!

       
Eric Barnes's avatar
Eric Barnes
487 posts
15 years ago
Eric Barnes's avatar Eric Barnes

Are you sure {member_id} is actually being set? Have you tried with a hard coded id: {ext:my_plugin:method my_param="2"}

       
ElephantMan's avatar
ElephantMan
3 posts
15 years ago
ElephantMan's avatar ElephantMan

Thanks for the quick response. Passing a hard-coded member id (like “18”) works fine and the plugin function returns the appropriate result. But passing “{member_id}” results in the function getting “{member_id}” instead of “18”. However, when I do <h1>{member_id}</h1> in my template then I get <h1>18</h1> as expected, so the {member_id} variable does work.

I’m brand new to EE. Is there maybe a setting somewhere that I need to tweak that controls nested tag evaluation?

Thanks!

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
15 years ago
Pascal Kriete's avatar Pascal Kriete

It’s a parse order issue (your plugin is being parsed before member_id).

You can change the parse order of plugins using parse=”inward”, as described at the bottom of this page.

However, if you’re looking the current member id, you’re best off just grabbing it from the session:

$member_id = $this->EE->session->userdata('member_id');
       
ElephantMan's avatar
ElephantMan
3 posts
15 years ago
ElephantMan's avatar ElephantMan

Fantastic, thank you Pascal!

       
webb_design's avatar
webb_design
11 posts
about 15 years ago
webb_design's avatar webb_design

I’m having this problem as well. I’m writing a plugin that returns weather info for a given location. When I hard code the location into the tag, it works fine. For example

{exp:weather:current location="94158"}

I’ve setup a global variable called “site_location”. When I use the global var in the parameter, it doesn’t work anymore. In the plugin, I’m getting {site_location}. I’ve tried setting the parse order, but that did not help.

Any help would be appreciated.

Thanks, daniel

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.