I am trying to use a variable from a plugin as a parameter inside an EE tag like so:
{exp:tscf:get_articles weblog_name="news"}
{exp:weblog:entries weblog="news" limit="6" status="important|open" paginate="bottom" dynamic="on" category="{cat}"}
{/exp:tscf:get_articles}
rest of exp:weblog:entries stuff...
where {cat} is the variable being returned from the plugin.
This doesnt render the exp:weblog tags at all..
I looked at the thread here: http://ellislab.com/forums/viewthread/33878/ What am I doing wrong?
Hiya vinci,
Don’t know if this will work or not but have you tried adding the parse=”inward” parameter to your plugin call as that can sometimes help. I tried doing something just like this a while back and must admit I never got it to work but this might in your case.
I was trying to simply send back a load of entry ids to the weblog entry_id parameter but could never get it to work though.
Hope this maybe works for you?
Best wishes,
Mark
Nope. That doesnt work.
In my plugin I have the following:
$tagdata = $TMPL->tagdata;
$tagdata = $TMPL->swap_var_single( 'cat', $embedded, $tagdata);
return $tagdata;
In the template I have:
{exp:tscf:get_articles weblog_name="news" parse="inward”}
{cat}
{exp:weblog:entries weblog="{blog}" limit="1" url_title="{segment_3}" status="open|important" category={cat}}
{/exp:tscf:get_articles}
{title}
{/exp:weblog:entries}
the first {cat} outputs the string correctly as: “45|66|77|23|1|56|90” (including the quotes)
After that the template outputs: {title} {/exp:weblog:entries}
Is there anyway to check if the second {cat} in the {exp:weblog:entries} tag is being processed?
Also just tried laying it up as:
{exp:tscf:get_articles weblog_name="news" parse="inward”}
{cat}
category={cat}
{exp:weblog:entries weblog="{blog}" limit="1" url_title="{segment_3}" status="open|important" category={cat}}
{title}
{/exp:weblog:entries}
{/exp:tscf:get_articles}
The first {cat} prints fine, as: “13|15|29|16|30|17|24” including the quotes. The second prints fine as well, as: category=”13|15|29|16|30|17|24” The third inside the weblog tags doesnt, from what I can tell, because the {title} tag doesnt give me any titles, and I know there are entries in those categories.
In your example above, you have:
{exp:weblog:entries weblog="{blog}" limit="1" url_title="{segment_3}" status="open|important" category={cat}}
You need:
{exp:weblog:entries weblog="{blog}" limit="1" url_title="{segment_3}" status="open|important" category="{cat}"}
See the added “quotes”?
ok, i added a conditional inside the tag, and now its broke..
{exp:tscf:get_articles weblog_name="news" parse="inward"}
{exp:weblog:entries weblog="news" limit="5" status="open|important" category={cat}}
{if no_results}
no results returned
{/if}
<h2>{title}</h2>
{/exp:weblog:entries}
{/exp:tscf:get_articles}
could someone tell me why this isnt working now?
vinci,
Parse order is not your friend here. And, sadly, using plugins to put values into entry tag parameters almost never works. I’m not going to say never as I’ve seen strange cases where it does but its not something we can support.
It’s dirty but you can do what you need by setting PHP to parse on input and having PHP code in the template find the categories and insert them into the parameter before the entries tag is parsed by EE.
Jamie
its seems to be quite unstable. one method works, and then the next moment it doest.
I have manage to avoid php.. but at the end of the day I might as well have anyway, because the solution is still quite round-about.
This works for me, but im not saying it will work for anyone else.
the single variable wont be parsed in the exp:weblog tags, but I did manage to get it working to embed a template with a passed variable:
main template:
{exp:tscf:get_articles weblog_name="news" parse="inward"}
{embed="news/news2" dog="{cat}"}
{/exp:tscf:get_articles}
and then in a separate template (news2 in my case):
{embed:dog}
{exp:weblog:entries weblog="news" limit="5" status="open|important" category="{embed:dog}"}
{if no_results}no results returned{/if}
{title}
{/exp:weblog:entries}
like I say, works for me, might need some experimenting though
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.