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

Plugin return values and template.php error

Development and Programming

spyro's avatar
spyro
89 posts
14 years ago
spyro's avatar spyro

I just wrote a plugin ( my first ) which is supposed to evaluate to a Boolean so that it can be used in a if statement, similar to {if logged_in}.

Here is the test template:

{if {exp:keyauth:auth}}

    Show secret data

{/if}

no access for you

When the plugin returns true everything works correctly but when the plugin returns false I get PHP errors in Template.php.

Parse error: parse error in C:\xampp\htdocs\rtrain\trunk\training\system\expressionengine\libraries\Functions.php(650) : eval()’d code on line 1

Is there another way that I should be doing this?

       
spyro's avatar
spyro
89 posts
14 years ago
spyro's avatar spyro

Apparently EE does not like you to return FALSE but happily allows return 0;

Does anyone have any suggestions on this scenario or a know why this occurs?

       
the3mus1can's avatar
the3mus1can
426 posts
14 years ago
the3mus1can's avatar the3mus1can

You could make it a tag pair and use $this->EE->functions->prep_conditionals() - http://ellislab.com/expressionengine/user-guide/development/reference/functions.html.

Template code would look like:

{exp:keyauth:auth}

    {if auth}
       .... more ...
    {/if}

{/exp:keyauth:auth}

Psuedo PHP plugin code:

public function auth() 
{
    $conditionals = array('auth' => TRUE);
    return $this->EE->functions->prep_conditionals($this->EE->TMPL->tagdata, $conditionals);    
}
       
spyro's avatar
spyro
89 posts
14 years ago
spyro's avatar spyro

Thanks for the feedback.

I need to go through prep_conditionals and see what it actually does as the documentation doesn’t really tell you how it “preps.”

       

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.