Page 1 of 1
CGCalendar: Passing event field name into a GBC
Posted: Tue Feb 14, 2017 6:57 pm
by cpansewicz
Hi,
Is it possible to pass a field name into the name of a global content block in an event template? This is CGCalendar 1.16.1.
For instance,
{if $event.fields.name != ""}
{global_content name='{$event.fields.name)'}
{/if}
Thank you,
Camille
Re: CGCalendar: Passing event field name into a GBC
Posted: Tue Feb 14, 2017 9:50 pm
by calguy1000
Single quotes are literals.... smarty does not expand their contents.
Smarty will attempt to expand the contents of double quotes.
But in this case, none of that matters.
{if $event.fields.name != ''}
{global_content name=$event.fields.name}
{/if}
Re: CGCalendar: Passing event field name into a GBC
Posted: Tue Feb 14, 2017 10:24 pm
by cpansewicz
Thank you so much. In a similar question, is it possible to code the template so that if I choose a category to place the event in, that category name will populate the name of the GBC?
So if choose my event to be under "General", then the GBC would be {global_content name='General'}? I've tried this is different ways, and haven't been able successfully code this.
Re: CGCalendar: Passing event field name into a GBC
Posted: Wed Feb 15, 2017 6:04 am
by cpansewicz
I started with:
{if $event.category_names == "General"}
{global_content name='General'}
{/if}
But that doesn't seem to work. Maybe because sometimes an event will be in several categories, so I would have to write, if the category name includes?
SOLVED: CGCalendar: Passing event field name into a GBC
Posted: Fri Feb 17, 2017 6:56 pm
by cpansewicz
In case anybody else is looking to do something similar, if you have an event that is in several categories, but want to sync content into the template based on one of those categories, this is the code that works:
{if strpos($event.category_names, 'General') == true}
Content here
{/if}
Thanks again for this forum.
Re: SOLVED: CGCalendar: Passing event field name into a GBC
Posted: Sun Feb 19, 2017 2:16 pm
by PinkElephant
Hi,
Thanks for posting the solution. I'm not familiar with the module but a quick note on the function...
cpansewicz wrote:{if strpos($event.category_names, 'General') == true}
strpos() returns Boolean FALSE or the numeric position of first instance using an index starting at zero. To avoid position '0' being evaluated as false an exact test is required:
Code: Select all
{if strpos($event.category_names, 'General') !== false}
(Untested in smarty context but it seems to be the way).
Re: CGCalendar: Passing event field name into a GBC
Posted: Mon Feb 20, 2017 6:36 am
by cpansewicz
Ok. Thanks for that clarification on that code. I appreciate it!