Page 1 of 1

$itemcount in custom News template returns nothing

Posted: Fri Jun 02, 2006 12:24 pm
by wfunderberg
Morning all,

I have successfully created a custom News template with no problems:

Code: Select all

{foreach from=$items item=entry}
<div class="sideBarText">{$entry->title}</div>
{/foreach}
However when I insert an if statement to test to see if there are any news items to display nothing seems to happen:

Code: Select all

{if $itemcount > 0}
{foreach from=$items item=entry}
<div class="sideBarText">{$entry->title}</div>
{/foreach}
{/if}
I even went as far as to just put

Code: Select all

{$itemcount}
in the template to see what number it would print out and it nothing came out of it. I noticed in the default News templates the code does include the IF statement and that works.
Any ideas as to why the $itemcount variable is not returning anything? Also, where can I find more information about variables such as $item, $entry, etc.,

thanks!
Wes

Re: $itemcount in custom News template returns nothing

Posted: Fri Jun 02, 2006 3:12 pm
by Dr.CSS
you can find your variables with a user defined tag..
call it 'whatever' or the blue hilite name, tag in template {whatever} or {get_template_vars}  it will spit out a lot of info... a lot of searching but useful

// get a list of all of the smarty assigned variables
// user defined tag named "get_template_vars"
global $gCms;
$tpl_vars = $gCms->smarty->get_template_vars();
print_r( $tpl_vars );

Re: $itemcount in custom News template returns nothing

Posted: Sat Jun 03, 2006 2:12 am
by Elijah Lofgren
wfunderberg wrote: Any ideas as to why the $itemcount variable is not returning anything?
It's because $itemcount is not a var. Thankfully using a User Defined Tag ("Admin Panel -> Extensions -> User Defined Tags") you can make it one.
I've posted instructions in the wiki here: http://wiki.cmsmadesimple.org/index.php ... news_items
wfunderberg wrote: Also, where can I find more information about variables such as $item, $entry, etc.,
News template vars need documentation. I've put it on my todo list.  ;)
wfunderberg wrote: thanks!
You're welcome.  :)

Re: $itemcount in custom News template returns nothing

Posted: Sat Jun 03, 2006 1:37 pm
by wfunderberg
But let me ask you this, how is it then that the $itemcount variable is found in the templates that come with the default News module and those seem to work? Am I missing something here?
Elijah Lofgren wrote:
wfunderberg wrote: Any ideas as to why the $itemcount variable is not returning anything?
It's because $itemcount is not a var. Thankfully using a User Defined Tag ("Admin Panel -> Extensions -> User Defined Tags") you can make it one.
I've posted instructions in the wiki here: http://wiki.cmsmadesimple.org/index.php ... news_items
wfunderberg wrote: Also, where can I find more information about variables such as $item, $entry, etc.,
News template vars need documentation. I've put it on my todo list.  ;)
wfunderberg wrote: thanks!
You're welcome.  :)

Re: $itemcount in custom News template returns nothing

Posted: Sat Jun 03, 2006 2:32 pm
by Elijah Lofgren
wfunderberg wrote: But let me ask you this, how is it then that the $itemcount variable is found in the templates that come with the default News module and those seem to work? Am I missing something here?
The $itemcount variable is used in the "admin" templates that come with the News module. I'm guessing you found it being used in templates/categorylist.tpl or templates/articlelist.tpl. Those are both used in the Admin Panel part of news.

However, it makes sense to make $itemcount a default template variable for the News front-end, so I've added this in the latest SVN version of the News module: http://viewsvn.cmsmadesimple.org/viewsv ... w=rev&nbsp; ;)

Re: $itemcount in custom News template returns nothing

Posted: Mon Jun 05, 2006 4:31 pm
by wfunderberg
Rock on!