CGCalendar not having foreach

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
andrewvideouk
Forum Members
Forum Members
Posts: 86
Joined: Thu Aug 20, 2020 10:49 pm

CGCalendar not having foreach

Post by andrewvideouk »

Hi amzing guys.

its prosbile to call up the fields without scaning with a foreach if I know the fields names been given already. How would I do it?

I am using assign to save the value for later use. I am showing a image if only a description (ALT) is pesent.

The code works below, I just want to make it simple and faster.

Thank you.

Code: Select all

{if $page_alias != "eventss"} 
                 		
  {foreach from=$events key=key item=event}
               {if $event.fields.Summary.field_value != '' || $event.event_details != ''}
   <div class="eventbox"> 
       <a href="{$event.url}" title="{$event.event_title}">
    <div class="eventpic">  
        {if isset($event.fields)}  
    {foreach $event.fields as $fieldname => $fieldrec}
     {if $fieldname == "Image"}
  {assign var="cal_image" value=$fieldrec.field_value}
      {/if}      
         {if $fieldname == "Image description"}
   {assign var="cal_des" value=$fieldrec.field_value}
      {/if}      
    {/foreach}    
    
{/if}

 {if $cal_des != '' && $cal_image != "" }    
    {CGSmartImage src={$cal_image} alt={$cal_des} filter_crop2size="300,140" }         
        {else}         
        {CGSmartImage src="https://www.webiste.org.uk/uploads/images/cal.jpg" alt={$event.event_title} filter_crop="300,140" }         
        {/if}      
        
             <p class="imgdate" ><span class="imgmonth">{$event.event_date_start|date_format:"M"}</span><br/><span class="imgday">{$event.event_date_start|date_format:"d"}</span></p>           
        {$event.event_date_start|date_format:"M d"}        
     </div>  
                {if $event.fgcolor != '' && $event.bgcolor != ''}
        <h3 >{$event.event_title}</h3>
      {else}
        <h3>{$event.event_title}</h3>
      {/if}
      {if $event.event_date_start == $event.event_date_end || $event.event_date_end == 0}
        {* event has no end date *}
        <p class="eventdate">{$event.event_date_start|date_format:"l dS F"}
        </p>
          {if $event.event_all_day == "0"}
			<p class="eventtime">{$event.event_date_start|date_format:"%H:%M"}</p>{/if}
      {else}
        {if $event.event_date_start|date_format:"%d%m%Y" == $event.event_date_end|date_format:"%d%m%Y"}
	   {* event starts and ends on the same day *}
		<p class="eventdate">{$event.event_date_start|date_format:"l dS F"}</p><p class="eventtime">{$event.event_date_start|date_format:"%H:%M"} - {$event.event_date_end|date_format:"%H:%M"}</p>
        {else}
	   {* event staarts and ends on different dates *}
          <p class="eventdate">{$event.event_date_start|date_format:"dS F"}   - {$event.event_date_end|date_format:"dS F"}</p> 
        {/if}
      {/if}    
      {if $event.fields.Summary.field_value != ''}
        <p>{$event.fields.Summary.field_value|strip_tags|truncate:300}</p>
          <p class="more">More Details</p>
      {elseif $event.event_details != ''}
        <p>{$event.event_details|strip_tags|truncate:300}</p>
        <p class="more">More Details</p>
        {else}<p>Sorry no infornation on this event</p>
      {/if}  
   </a></div>
   {/if}
  {/foreach}
{/if}
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1154
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: CGCalendar not having foreach

Post by DIGI3 »

If there's a way to directly access them it's not documented that I can see. You can get to them without a nested foreach as long as you're in the events loop with:

Code: Select all

{$event.fields.foo.field_value}
Or outside of the loop if you know the index of your event:

Code: Select all

{$events[index].fields.foo.field_value}
where foo is the field name

The documentation says you can use event.fields.fieldname but my tests showed that returned an array, and the .field_value part is needed.
Not getting the answer you need? CMSMS support options
andrewvideouk
Forum Members
Forum Members
Posts: 86
Joined: Thu Aug 20, 2020 10:49 pm

Re: CGCalendar not having foreach

Post by andrewvideouk »

Thank you. Its anyway can get to work with spaces in the names?
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1154
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: CGCalendar not having foreach

Post by DIGI3 »

I think you should be able to assign the field name to a variable first:

Code: Select all

{$temp='my field name with spaces'}
{$event.fields.$temp.field_value}
Not getting the answer you need? CMSMS support options
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3322
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: CGCalendar not having foreach

Post by velden »

Probably this works too:

Code: Select all

{$event.fields['my field name with spaces'].field_value}
https://www.smarty.net/docs/en/language ... soc.arrays
andrewvideouk
Forum Members
Forum Members
Posts: 86
Joined: Thu Aug 20, 2020 10:49 pm

Re: CGCalendar not having foreach

Post by andrewvideouk »

Thank you. I will try that
Post Reply

Return to “Modules/Add-Ons”