Page 1 of 1

Accessing variables from within modules

Posted: Fri Mar 12, 2010 11:42 pm
by bigredthelogger
Hello everyone.

I have three modules News, CGBlog, and CGCalendar that my client users to post News, Events and Blog items.

The client does not want the side bar titles News, Blog, or Events to appear if there are none.

The below link explains how to user a User Defined Tag for News, but $itemcount seems to be used for multiple mods, so I am not sure how to get it.

Is there not a way i can access the object of a module directly and the array?

http://wiki.cmsmadesimple.org/index.php ... fined_Tags

Re: Accessing variables from within modules

Posted: Sat Mar 13, 2010 9:03 am
by Jos
Yes, you don't need a UDT for this.

You can change the moduletemplate for each module a bit by adding some smarty code.
Most modules have a variable like $itemcount, but they don't need to, or the name may vary slighly. This is how you caan do it for all cmsms modules:

You have to determine which moduletemplates you use. For News I guess you can find it in the tab "Summary Templates". The templates there use something like this:

Code: Select all

{foreach from=$items item=entry}
So the variable $items is the array with all the newsitems here.

On the fisrt row of that moduletemplate you put:

Code: Select all

{if $items|@count > 0}
and on the last row:

Code: Select all

{/if}
In CGBlog there is also the variable $items.
CGCalendar uses $events as array variable in the "Upcoming Templates".

Re: Accessing variables from within modules

Posted: Sat Mar 13, 2010 4:09 pm
by bigredthelogger
Thanks for your reply.

I am able to do those from within the summary template however, the issue is I have a side bar with 3 categories (News, Events, Calendar).  My client does not even want the categories to appear if there are no News, Events, or Blog entries.

So I need a way to access to basically have something like {if news itemcount != 0} but fromwithin a global content block

Re: Accessing variables from within modules

Posted: Sat Mar 13, 2010 4:39 pm
by Jos
Why don't you put the in the moduletemplate also?  ;)

Re: Accessing variables from within modules

Posted: Sat Mar 13, 2010 5:43 pm
by bigredthelogger
Haha your a genius :)