Showing the Title in a Calendar Navigation Object When Not On the Calendar Page

Here at Cage I have started the process of moving one of our older sites into Mura. The organization is an educational non-profit so needless to say they have a lot of involvement in educational functions. One page on their website is a calendar of STEM (Science, Technology, Engineering, and Mathematics) events throughout the state of Connecticut and with that they will have a calendar navigation content object on the home page so that people can quickly see if events are coming up.

One problem with the calendar navigation component as is is that it does not display the title of the calendar so people can’t see what they are looking at. If we just blindly throw the title onto it for every page then we will show it on the Calendar page (if the content object is displayed there) which causes a bit of unnecessary redundancy. So I came up with a solution that was surprisingly quick as follows:

Create the Customer Display Object for the Calendar Navigation

In past versions of Mura custom display objects were per site, meaning that if you wanted a custom display object is was attached to the site you added it to (unless you created a plugin for the display object). In more recent versions of Mura though the guys at Blue River added a new feature to create custom display objects per theme, meaning that any site that the theme was installed on could use that display object. Since I am building the theme for the client on a different Mura install I decided to go the per theme direction. The way to create a custom display object is to find the stock display object in the folder, {siteid}/includes/display_objects, and copy it to your theme, {siteid}/includes/{theme}/display_objects. The calendar navigation can be found in {siteid}/includes/display_objects/nav/calendarNav.

Customizing Our Display Object

Now that we have our custom calendar navigation display object lets look at alittle of the details on how it works by opening the index.cfm file. You will notice that it takes the argument of objectID which it sets to navID. This is the Content ID of the calendar that the navigation is for. From that ObjectID it gets the filename, menutitle, and type from the database which is used throughout the rest of the display object. It then builds a few variables needed and then builds the actual display area.

Customizing the CFM Output

The first thing we need to do is set the calendar title to a new variable. So underneath the variable settings lets put this line:

Now that we have the Calendar title in a variable we have to check if we are actually going to use it.  For that is a simple if statement to tell if the navID variable defined earlier is the same as the current content ID.  The code to do that is as follows:

We now know what the title is and whether or not to use them we need to pass the variables into the setParams function.  Simply put the two variables we created at the end of the function call lie so:

Customizing the CFC Output

We are now done with the index.cfm file so we can go ahead and close it.  Lets open up the navTools.cfc file to start working with that.

navTools.cfc is made up of just a few functions (getNavID, dspDay, setParams, and dspMonth) although we are only concerned with the last two (setParams and dspMonth).  The first thing we need to do is set our extra arguments to parameters in the setParams function.  To do so we need to add a couple arguments and a couple param settings.

The new function will make the new parameters accessible by the dspMonth function so lets jump down to there.  Like most of the editing we have done so far the dspMonth function only requires a couple of lines as well.  We need to check if we are showing the title again and then displaying it if we are.

Just copy that line after the opening table tag and it will display the title with a link to the calendar.

That's it.  We have now added the title of the calendar to the calendar navigation only when we are not on the calendar page.

A full download is available on GitHub as a Gist here.

You can also clone the gist and customize it further on GitHub

Comments

Post a Comment
  1. Leave this field empty

Required Field