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 do you use $TMPL->no_results()?

Development and Programming

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

Hiya,

Hopefully this is an easy one for someone to answer.

I am currently making a plugin and I would like to utilise :

{if no_results}
Sorry no results here!!
{/if}

I tried this in a plugin :

function Test_plugin(){
global $TMPL;
return $TMPL->no_results();
}

with obviously the rest of the needed plugin code around it such as class etc but all I get is an empty page spat out. Nothing in the source code apart from the rest of the HTML markup that I have placed in there.

I just need to be able to create a no_results conditional so that if my plugin has no results then I can place a message on the screen. I had seen this done in other plugins / extensions and can’t really see where I am going wrong. I thought it was just as simple as placing :

return $TMPL->no_results();

into my plugin and then the text between my conditional tag in the template would show but it seems like there must be more to it than that as nothing is being spat out to the page at all.

Any help with understanding this would be greatly appreciated.

Thanks in advance for any help on this one.

Best wishes,

Mark

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

Hmm slight update.

Out of sheer frustration I was just coding all things that I know about plugins etc (which at this moment in time I don’t think is much! 😉 ) and tried this :

$this->return_data = $TMPL->no_results();

This works fine and in my template I can now use :

{if no_results}
There's nothing to see here!!
{/if}

Just wondering if this is okay to do or not? It seems to work fine but I had noticed in other peoples extensions and plugins that all they had ever done is :

return $TMPL->no_results();

This is even in the mod.weblog.php file and I am just wondering why it wouldn’t work in that way for me and I had to place more code in front to get it to work.

Any information as to whether I have done this right or wrong or how I should be doing it or why it does / doesn’t work would be great thanks as I am really trying to get my head around understanding all of this.

Thanks.

Best wishes,

Mark

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Hey Mark,

From the docs:

There are two ways to return a value depending on whether your tag has three segments or two.

Two Segments ex: {my:plugin} must use:

this->return_data = 'foo'

but three segments ex: {my:plugin:method} can return the value directly

return 'foo';

For more information visit: http://expressionengine.com/docs/development/plugins.html and search for: “Returning A Value”

Cheers Leevi

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

Hi Leevi,

Thanks for that. Must have blinked when reading the documents as I never saw that. Thanks for the pointers and the documentation link. Will try to remember that for the future now 😉

Thanks again.

Best wishes,

Mark

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

No worries mark… I know how after staring at a screen for so long things can just cbecome a blur 😊

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen
No worries mark… I know how after staring at a screen for so long things can just cbecome a blur 😊

So you at least get a blur eh?

My screen (or is it my brain) just goes completely blank sometimes!! 😉 😊 😉

Thanks again for the pointers, much appreciated. Hope things are going well for you.

Best wishes,

Mark

       

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.