[Solved] Extract events from CGCalendar 1.15

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
leoteo

[Solved] Extract events from CGCalendar 1.15

Post by leoteo »

Dear forum,

for some time I have been using the CGFeedmaker module in conjunction with the CGCalendar module to generate RSS feeds from upcoming calendar events.
The relevant code from the feed template inside CGFeedmaker reads

Code: Select all

...
{capture assign='kalender'}
 {* note that the output from this module call is discarded, but the smarty variables will still exist *}
 {cms_module module='CGCalendar' display=upcominglist'}
{/capture}   

{foreach from=$events key=key item=event}
...
It seems that since version 1.15, CGCalendar no longer exports the $events array, as also mentioned in the release notes
Note: We now create a separate smarty scope for each visible template to prevent smarty variable name collision issues, and for memory optimization purposes. This may cause problems when trying to export variables to other templates, or when trying to use a variable created in another template.
I have two questions:
1) Is there still a way to get this array directly from CGCalendar? I looked at the exported variables with {get_template_vars}, but was not able to find anything.

2) If not, what is the best way to do it? I guess I could manually modify the CGCalendar templates to fill up such an array structure, but maybe there is a better way..

Best regards,
leoteo
Last edited by leoteo on Mon Oct 05, 2015 8:58 am, edited 1 time in total.
leoteo

Re: Extract events from CGCalendar 1.15

Post by leoteo »

*bump*
Anybody? I would have thought that using variables exported by one module in another module is not so uncommon - a solution to this issue might be helpful also in several other use cases, if more modules start using smarty scopes.

Or maybe I am just missing a very easy solution? I am not familiar with how smarty scopes work, any help would be greatly appreciated.
If the original question is not clearly formulated, please also let me know.

Best,
leoteo
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Extract events from CGCalendar 1.15

Post by calguy1000 »

a: don't use capture unless absolutely necessary. it is very slow.
b: this is also demonstrated in CMSMS 2.0 where smarty scopes are used throughout the system.

To export a variable for use in another template you need to explicitly export the data.

Modify your upcoming list template to export the data to a global smarty variable.
something like:

Code: Select all

{$calendar_events=$events scope=global}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
leoteo

Re: Extract events from CGCalendar 1.15

Post by leoteo »

Dear calguy1000

thank you so much, this looks like exactly what I was looking for!

I tried to get it to work, but for some reason I am not succeeding.
I added the line to the upcominglisttemplate as you suggested, and I checked that, after this line, the variable $calendar_events is properly populated (within the template).
I then tried to use the $calendar_events variable in the CGFeedmaker template. I have tried both the capture approach shown above as well as

Code: Select all

{cms_module module="CGCalendar" assign="junk" display="upcominglist" upcominglisttemplate="Homepage" limit="10"}
However, after this line (or the capture block) the $calendar_events variable remains unset.

Should this approach work in principle or am I still missing some general point?

Best,
leoteo
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Extract events from CGCalendar 1.15

Post by calguy1000 »

Okay. I was a bit off on my last reply, merely because of the way smarty works (variables are passed in from global variables when the template is created, etc).

but anyways.... since this is a CGExtensions derived module the solution is quite simple:

a: in your CGCalendar template instead of the {$calendar_events=....} stuff do this:
{cge_tmpdata::set('calendar_events',$events)}

b: in your CGFeedmaker template
{CGCalendar display=upcominglist assign='junk'}
{$events=cge_tmpdata::get('calendar_events')}

You may also have to set permissive_smarty in the config.php
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
leoteo

Re: Extract events from CGCalendar 1.15

Post by leoteo »

Dear calguy1000

thank you very much, this solves it!

Best regards,
leoteo
Locked

Return to “Modules/Add-Ons”