$itemcount in custom News template returns nothing

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
wfunderberg
Forum Members
Forum Members
Posts: 42
Joined: Tue Mar 28, 2006 8:05 pm

$itemcount in custom News template returns nothing

Post 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
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: $itemcount in custom News template returns nothing

Post 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 );
User avatar
Elijah Lofgren
Power Poster
Power Poster
Posts: 811
Joined: Mon Apr 24, 2006 1:01 am
Location: Deatsville, AL

Re: $itemcount in custom News template returns nothing

Post 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.  :)
Note: I don't have time to take on any more projects. I'm quite busy. I may be too busy to reply to emails or messages. Thanks for your understanding. :)
wfunderberg
Forum Members
Forum Members
Posts: 42
Joined: Tue Mar 28, 2006 8:05 pm

Re: $itemcount in custom News template returns nothing

Post 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.  :)
User avatar
Elijah Lofgren
Power Poster
Power Poster
Posts: 811
Joined: Mon Apr 24, 2006 1:01 am
Location: Deatsville, AL

Re: $itemcount in custom News template returns nothing

Post 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; ;)
Note: I don't have time to take on any more projects. I'm quite busy. I may be too busy to reply to emails or messages. Thanks for your understanding. :)
wfunderberg
Forum Members
Forum Members
Posts: 42
Joined: Tue Mar 28, 2006 8:05 pm

Re: $itemcount in custom News template returns nothing

Post by wfunderberg »

Rock on!
Post Reply

Return to “Developers Discussion”