Accessing variables from within modules

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
bigredthelogger
New Member
New Member
Posts: 4
Joined: Mon Feb 22, 2010 11:08 pm

Accessing variables from within modules

Post 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
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: Accessing variables from within modules

Post 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".
bigredthelogger
New Member
New Member
Posts: 4
Joined: Mon Feb 22, 2010 11:08 pm

Re: Accessing variables from within modules

Post 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
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: Accessing variables from within modules

Post by Jos »

Why don't you put the in the moduletemplate also?  ;)
bigredthelogger
New Member
New Member
Posts: 4
Joined: Mon Feb 22, 2010 11:08 pm

Re: Accessing variables from within modules

Post by bigredthelogger »

Haha your a genius :)
Post Reply

Return to “Developers Discussion”