CGCalendar change interval of event times from 15 minutes

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Location: Maidenhead, UK
Contact:

CGCalendar change interval of event times from 15 minutes

Post by paulbaker »

Edited 18 Dec 2012 to use the better method described in the first few replies below. Edited 5 Dec 2018 to use "assets" folder.

CGCalendar is very lovely for displaying events in different ways on your website. The default granularity when you add/edit events is every 15 mintes: so 00, 15, 30, 45 minutes past the hour. The time is entered as a dropdown box.

What if you have an event that starts at 15:10? You then need to change the time dropdown box to show every 5 minutes: so 00, 05, 10, 15, 20....through to 55.

Here's how. (See the Customizing Admin templates page of the docs area for the general method.)

Create a new directory assets/module_custom/CGCalendar/templates/

Copy the 3 files admin_add_event.tpl, orig_editevent_template.tpl, settings.tpl from modules/CGCalendar/templates/ across to your new directory.

Open assets/module_custom/CGCalendar/templates/admin_add_event.tpl
Search for "interval=" and around line 105 you will see

Code: Select all

<span id="starttime"{if $event.all_day_event == 1} style="display: none;"{/if}> @ {html_select_time use_24_hours=$use24 prefix=$tmp time=$event.event_date_start_ut minute_interval=15 display_seconds=false}</span>
Change the 15 to 5 (or whatever)

Search for "interval=" and around line 117 you will see

Code: Select all

{html_select_date prefix=$tmp  time=$event.event_date_end_ut start_year=$start_year end_year=$end_year}<span id="endtime"{if $event.all_day_event == 1} style="display: none;"{/if}><br/>@ {html_select_time use_24_hours=$use24 time=$event.event_date_end_ut prefix=$tmp minute_interval=15 display_seconds=false}</span>
Change the 15 to 5 (or whatever)


Open assets/module_custom/CGCalendar/templates/orig_editevent_template.tpl
Search for "interval=" and around line 47 you will see

Code: Select all

<span id="starttime"{if $event.all_day_event == 1} style="display: none;"{/if}> at {html_select_time use_24_hours=$use24 prefix=$tmp time=$event.event_date_start_ut minute_interval=15 display_seconds=false}</span>
Change the 15 to 5 (or whatever)

Search for "interval=" and around line 58 you will see

Code: Select all

<span id="endtime"{if $event.all_day_event == 1} style="display: none;"{/if}> at {html_select_time use_24_hours=$use24 time=$event.event_date_end_ut prefix=$tmp minute_interval=15 display_seconds=false}</span>
Change the 15 to 5 (or whatever)


Open assets/module_custom/CGCalendar/templates/settings.tpl
Search for "interval=" and around line 108 you will see

Code: Select all

{html_select_time prefix=$tmp display_seconds=false time=$dflt_starttime minute_interval=15}
Change the 15 to 5 (or whatever)

And you're done ;D
Time drop down showing 5 minute intervals
Time drop down showing 5 minute intervals
5minutes.jpg (35.31 KiB) Viewed 6965 times
Last edited by paulbaker on Tue Dec 18, 2012 5:15 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: CGCalendar change interval of event times from 15 minute

Post by calguy1000 »

Please revise this post to use the module_custom technique instead of modifying distributed files :)
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.
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Location: Maidenhead, UK
Contact:

Re: CGCalendar change interval of event times from 15 minute

Post by paulbaker »

Sorry, I thought we were allowed to modify template files. I will modify the solution and post again when I have done so.
User avatar
manuel
Power Poster
Power Poster
Posts: 353
Joined: Fri Nov 30, 2007 9:15 am

Re: CGCalendar change interval of event times from 15 minute

Post by manuel »

Dear Paul,

You will need to create the folder "module_custom/modules/CGCalendar/templates/"
Then, create blank files named "admin_add_event.tpl", "orig_editevent_template.tpl" & "settings.tpl"

In the content of these files you will need to search & replace the stuff you want to change by using regex_replace.

Below an example for the blank admin_add_event.tpl file:

Code: Select all

{include file='file:##REPLACE_WITH_YOUR_SERVER_PATH##/modules/CGCalendar/templates/admin_add_event.tpl' assign='capturedtemplate'}
{$capturedtemplate|regex_replace:"/(##STUFF TO SEARCH FOR##)/":"##REPLACE WITH##"}
(note: i think that by including the file, the smarty code will aready be parsed... maybe you will need to use fetch? http://www.smarty.net/docsv2/en/languag ... .fetch.tpl )

I usually like to test regex_replace in http://gskinner.com/RegExr/

ps: When you convert it for usage in CMSMS you will need to "escape" some stuff with a backslash! (/ becomes \/)

The big advantage of using module_custom to make template changes is that can upgrade the modules without overwriting your changes! ;D

Greetings,
Manuel
Do you like your open source cms? Buy from the CMSMS partners || Donate
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Location: Maidenhead, UK
Contact:

Re: CGCalendar change interval of event times from 15 minute

Post by paulbaker »

Thanks for the reply Manuel. I found a help document in docs about module_custom:
http://docs.cmsmadesimple.org/customizi ... -templates

In that, the suggestion is you paste the standard template in to your custom one, and alter it as necessary.

I suppose your method of grabbing the standard template each time and altering it with a regex is even better because if the standard template changes in future versions the changes will be preserved (unless the standard template changes the exact bit your regex is searching for, of course).
You will need to create the folder "module_custom/modules/CGCalendar/templates/"
I don't think you need "modules/" in there?

I tried your method but I can't get it working.

In new file /home/cthuk/public_html/stmarys/module_custom/CGCalendar/templates/admin_add_event.tpl I have put:

Code: Select all

{include file='file:/home/cthuk/public_html/stmarys/modules/CGCalendar/templates/admin_add_event.tpl' assign='capturedtemplate'}
{$capturedtemplate|regex_replace:"/(minute_interval=15)/":"minute_interval=1"}
(I have put the original standard template files back so "minute_interval=15" does appear). The system is grabbing the .tpl file OK but the regex is not replacing the text.

I tried "{fetch file=..." but that didn't seem to work at all - just gave me a blank screen.

What am I doing wrong? ???
User avatar
manuel
Power Poster
Power Poster
Posts: 353
Joined: Fri Nov 30, 2007 9:15 am

Re: CGCalendar change interval of event times from 15 minute

Post by manuel »

Dear Paul,

Below a quick test you can perform:

Code: Select all

{include file='file:/home/cthuk/public_html/stmarys/modules/CGCalendar/templates/admin_add_event.tpl' assign='capturedtemplate'}
INCLUDE: {$capturedtemplate|@debug_print_var:0:600}
<br><br>
{fetch file='/home/cthuk/public_html/stmarys/modules/CGCalendar/templates/admin_add_event.tpl' assign='capturedtemplate2'}
FETCH: {$capturedtemplate2|@debug_print_var:0:600}
When you "fetch" the file, you will need to "eval" the template to execute the smarty inside ;)

Code: Select all

{eval var=$capturedtemplate2}
Greetings,
Manuel
Do you like your open source cms? Buy from the CMSMS partners || Donate
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: CGCalendar change interval of event times from 15 minute

Post by psy »

Manuel

IMHO, it seems to me like an lot of extra, unnecessary work. With module_custom, all you need do is create the comparable path, eg

Code: Select all

module_custom/MyModule/templates
Then create your customised template. Easiest way is to copy/paste the original then edit it as you wish.

Yes, module developers occasionally change templates in new versions, but that is an issue for us all anyway, whether frontend or admin, and hardly seems worth the additional overhead in 99.9% of cases. As Paul says, chances are the template change will affect the REGEX anyway so you'd still have to update the module_custom version.

I prefer to keep it simple. :)
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Location: Maidenhead, UK
Contact:

Re: CGCalendar change interval of event times from 15 minute

Post by paulbaker »

Thanks manuel but I agree with psy on this, keep it simple. ;D

I have now edited the original post to use the module_custom technique; copying the template files and editing the copies.
Post Reply

Return to “Tips and Tricks”