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

use field in limit

How Do I?

captainahab's avatar
captainahab
14 posts
4 years ago
captainahab's avatar captainahab

Hi, I need to set the limit in a channel entries tag with the value of a select – show 6|9|12 entries – field.

{exp:channel:entries channel="channelname" limit="{newscount}” {newscount} is a template partial with an entries tag and is rendered correctly when used outside the above entries tag. Looks like the channel entries tags are rendered at the same time and the limit variable is alway empty.

Thanks for any suggestion!

       
Andy McCormick's avatar
Andy McCormick
183 posts
4 years ago
Andy McCormick's avatar Andy McCormick

You’re correct in what the issue is. What you need to use is an embed vs a partial. A partial’s code is basically copied and pasted in the parent template and then the template is parsed. So you essentially end up with something like this the following, which is invalid.

{exp:channel:entries 
    channel="channelname" 
    limit="{exp:channel:entries channel="anotherchannel"}...{/exp:channel:entries}"
}

...

{/exp:channel:entries}

An embed is parsed first, then the output of that will be parsed when the parent template is parsed.

       
captainahab's avatar
captainahab
14 posts
4 years ago
captainahab's avatar captainahab

Hi Andy, thank you for your suggestion, unfortunately it does not work for me.

{embed="index/newscount"}

will return 12, but

{exp:channel:entries channel="news | otherchannel" search:show_in_news="not IS_EMPTY" limit='{embed="index/newscount"}' orderby="date" sort="desc" disable="category_fields|member_data|pagination|relationships"}

returns all entries for news | otherchannel.

       
Andy McCormick's avatar
Andy McCormick
183 posts
4 years ago
Andy McCormick's avatar Andy McCormick

try adding parse="inward" to the {exp:channel:entries channel="news | otherchannel"... tag

       
captainahab's avatar
captainahab
14 posts
4 years ago
captainahab's avatar captainahab

Still not working.

       
Andy McCormick's avatar
Andy McCormick
183 posts
4 years ago
Andy McCormick's avatar Andy McCormick

hm. you’re right. I just tested this several ways and couldn’t get it to work. Can you share both your templates here. There might be a different approach here. The other option is if you’re handy with PHP at all, it might be worth it to write a quick add-on to do this.

       
captainahab's avatar
captainahab
14 posts
4 years ago
captainahab's avatar captainahab

This is the template for the limit count, the field {news_total_count} is a select with key/value pairs.

{exp:channel:entries channel="homepage" disable="categories|category_fields|member_data|pagination|relationships"}
{news_total_count:value}
{/exp:channel:entries}
       

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.