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

How can I use $TMPL->no_results(); in a plugin?

Development and Programming

Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Hiya,

Hopefully a very quick one this. I am trying to create an exceptionally simple plugin which basically performs a database query and then the result will either be one row of data or none.

What I then want to do within my plugin is :

If there is a result then carry on and spit out the tagdata using :

$this->return_data = $tagdata;

If there isn’t a result then I want to display some text or code or whatever is placed in between :

{if no_results}
Text to show if no results
{/if}

The problem that I have though is that this plugin is placed within a weblog entries tag so I am ending up with something like this :

{exp:weblog:entries weblog="default_site" disable="member_data|trackbacks|pagination|categories|category_fields"}
{exp:my_plugin entry_id="{entry_id}"}
{if no_results}
No results here I'm afraid
{/if}
This will show if there are results
{/exp:my_plugin}
{/exp:weblog:entries}

Basically this will be going on a single entry page so (without giving too much away about the plugin if I may) I will be passing in the entry_id from the weblog entries tag and then using that in a simple database query which will then either return a result or not return a result.

I think the problem I have though is that I can’t use the no_results function as that is used in the weblog entries tag and so it is interfering with when I want to use it.

I then tried making my own conditional variable which sort of works so when there is a result the tagdata is spat out just as though the plugin wasn’t there but when there isn’t a database query result then I not only get the conditional results but also the plugin output too.

Is there any easy way of using the no_results function inside a plugin which is placed inside of a weblog entries tag?

Thanks for any help on this one.

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Slight update.

I just tried this :

{exp:weblog:entries weblog="default_site" limit="1"}

{exp:my_plugin entry_id="{entry_id}"}

{if no_access}
No results here = no_access
{if:else}
This shows if you do own the entry
{/if}

{/exp:my_plugin}

{/exp:weblog:entries}

This seems to work fine but I would rather not have to place the code that I would like to have working inside an {if:else} structure if possible. Not really sure if it matters or not or will cause any other problems any further down the line but would really like to be able to use an {if no_results} conditional instead if this is possible?

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Any of the EllisLab developers care to lead me down the right path on this one at all? 😉

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Oh well never mind.

Will carry on the way I have been instead then.

Best wishes,

Mark

       
BackBeat Media's avatar
BackBeat Media
76 posts
16 years ago
BackBeat Media's avatar BackBeat Media

Hey Mark,

Did you ever figure this out? I have the same problem {exp:podcastinfo} in a {exp:weblog:entries} tag, and I need to know if {url_path} is empty or not.

I tried a conditional right in my plugin ee tag, but it didn’t work as expected… do you need to do anything special to make your plugin variables work in conditionals?

I then tried

if ( empty($this->info["url_path"]) )
{
$this->return_data = $TMPL->no_results();
}

but like you said, it conflicts with exp:weblog:entries. I tried $TMPL->no_access(); but it didn’t work… do you have to do anything special in the php to make no_access work… do I need to make a no_access function somewhere?

Thanks! ~Stephen

       

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.