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

custom plugin variable as exp:weblog:entries tag parameter

Development and Programming

vinci's avatar
vinci
85 posts
17 years ago
vinci's avatar vinci

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?

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

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

       
vinci's avatar
vinci
85 posts
17 years ago
vinci's avatar vinci

Hi Mark. I’ll try it out.. thanks for the assistance

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

No problem. I hope it works for you. If not then I’m sure one of the excellent admins around here can give a lending hand? 😉

Best wishes,

Mark

       
vinci's avatar
vinci
85 posts
17 years ago
vinci's avatar vinci

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?

       
vinci's avatar
vinci
85 posts
17 years ago
vinci's avatar vinci

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.

       
vinci's avatar
vinci
85 posts
17 years ago
vinci's avatar vinci

hard coding the category = “13|15|29|16|30|17|24” in the exp:weblog:entries tag gives the correct results. so the plugin variable isnt being inserted there.

       
vinci's avatar
vinci
85 posts
17 years ago
vinci's avatar vinci

ok for some reason its now randomly working without touching anything. I think enclosing the custom plugin tags around the WHOLE exp:weblog tag pair may have helped.

       
Mr. Wilson's avatar
Mr. Wilson
131 posts
17 years ago
Mr. Wilson's avatar Mr. Wilson

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”?

       
vinci's avatar
vinci
85 posts
17 years ago
vinci's avatar vinci

Thanks, but the quotes are included in the string that is returned by the plugin. i.e. 56|45|76|23|46|12 is actually output as “56|45|76|23|46|12” so it isnt a problem.

Besides, its working 100% now (although Im not sure what I did). Thanks for all the help guys.

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

Hiya vinci,

Glad it’s all working for you now. Good luck with everything.

Best wishes,

Mark

       
vinci's avatar
vinci
85 posts
17 years ago
vinci's avatar vinci

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?

       
Jamie Poitra's avatar
Jamie Poitra
409 posts
17 years ago
Jamie Poitra's avatar Jamie Poitra

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

       
vinci's avatar
vinci
85 posts
17 years ago
vinci's avatar vinci

euuuuch shudders

       
vinci's avatar
vinci
85 posts
17 years ago
vinci's avatar vinci

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

       

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.