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
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
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
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.