Page 1 of 1

[SOLVED] Number of CGBlog articles

Posted: Wed Feb 26, 2014 2:09 pm
by nervino
Hello,
in my template I put

Code: Select all

{CGBlog category="events"}
I need to know the number of CGBlog items showed (maybe, there could be only 1 or 2 articles for that category), in order to use it to adapt a div height in the template.
For example, if that tag will output 3 items, I need that number in a smarty variable.

Which is the best way to do it?

thanks

Re: Number of CGBlog articles

Posted: Wed Feb 26, 2014 2:49 pm
by JohnnyB
You can assign it to a variable in your summary template

Code: Select all

{capture assign='articlecount'}{$items|@count}{/capture}
Then use {$articlecount} in your page/template. When using the category parameter, it should count just the articles available for that category.

Re: Number of CGBlog articles

Posted: Wed Feb 26, 2014 2:52 pm
by zaidcrowe
I have'nt used this for a while - but i think this will use the Summary template to create it's output (if not the following should still be of use!)

In the template look for something like:

{foreach from=$items item=entry}

To get the number of items and assign it to a variable use:

{assign var="cat_count" value=$items@|count}

To use that variable in your template simple use:

{$cat_count}

Re: Number of CGBlog articles

Posted: Wed Feb 26, 2014 3:26 pm
by velden

Code: Select all

{assign var="cat_count" value=$items@|count}
should be

Code: Select all

{assign var="cat_count" value=$items|@count}
I guess

Re: Number of CGBlog articles

Posted: Wed Feb 26, 2014 4:00 pm
by zaidcrowe
im either blind - or their both the same...

Re: Number of CGBlog articles

Posted: Wed Feb 26, 2014 4:02 pm
by velden
small change: @| vs. |@

Re: Number of CGBlog articles

Posted: Wed Feb 26, 2014 4:57 pm
by zaidcrowe
ahhh - interesting - is that a smarty 3 thing, or a different function - swear I always used my version and it was ok :S

Re: Number of CGBlog articles

Posted: Wed Feb 26, 2014 5:49 pm
by JohnnyB
not a smarty 3 thing because smarty 3 doesn't need the @.
Smarty 2 does though

Re: Number of CGBlog articles

Posted: Thu Feb 27, 2014 9:54 am
by zaidcrowe
thanks for the info :)

Re: Number of CGBlog articles

Posted: Thu Feb 27, 2014 12:32 pm
by nervino
Thank you All!