Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Last active September 18, 2018 12:48
Show Gist options
  • Save stevewithington/18a6ef38e7234f1e1fc3 to your computer and use it in GitHub Desktop.
Save stevewithington/18a6ef38e7234f1e1fc3 to your computer and use it in GitHub Desktop.
Mura CMS : Example of how to get upcoming calendar events by Feed name
<!---
https://gist.github.com/stevewithington/18a6ef38e7234f1e1fc3
1) Drop this in your Site or Theme contentRenderer.cfc
2) To use, drop the following line of code in your layout template, and modify as you wish:
#$.getUpcomingEventsByFeedname(feedname='Your Feed Name', maxMonths=2, groupDailyEvents=true)#
--->
<cffunction name="getUpcomingEventsByFeedname">
<cfargument name="feedName" type="string" required="true" />
<cfargument name="maxMonths" type="numeric" default="3" />
<cfargument name="groupDailyEvents" default="true" />
<cfscript>
var rs = '';
var subRS = '';
var local = {};
local.feed = variables.$.getBean('feed').loadBy(name=arguments.feedName).setMaxItems(0).setNextN(0);
local.listIDs = '';
if ( feed.getIsNew() ) {
return '<div class="alert alert-info"><strong>Ooops!</strong> The Content Collection/Feed &quot;<strong>#HTMLEditFormat(arguments.feedName)#</strong>&quot; does not exist.</div>';
}
local.it = feed.getIterator(
from=Now()
, to=DateAdd('m', Val(arguments.maxMonths), Now())
);
rs = local.it.getQuery();
</cfscript>
<cfsavecontent variable="str">
<cfoutput>
<div class="mura-index">
<div>
<cfloop condition="local.it.hasNext()">
<cfset local.item = local.it.next() />
<cfif not ListFind(local.listIDs, local.item.getValue('contentid'))>
<dl>
<!--- date --->
<dt class="date releaseDate">
#LSDateFormat(local.item.getValue('displayStart'))#
<!--- end date (if 'daily' event, and grouping is requested) --->
<cfif YesNoFormat(arguments.groupDailyEvents)>
<cfquery dbtype="query" name="subRS">
select *
from rs
where rs.contentid = <cfqueryparam value="#local.item.getValue('contentid')#" />
</cfquery>
<cfif subRS.recordcount gt 1>
<cfset enddate = ListLast(ValueList(subRS.displaystop)) />
<cfif IsValid('date', enddate)>
- #LSDateFormat(enddate)#
</cfif>
</cfif>
<cfset local.listIDs = ListAppend(local.listIDs, local.item.getValue('contentid')) />
</cfif>
</dt>
<!--- Title --->
<dt>
<a href="#local.item.getURL()#">
#HTMLEditFormat(local.item.getValue('title'))#
</a>
</dt>
<!--- Summary --->
<cfif Len(local.item.getValue('summary'))>
<dd class="summary">
#local.item.getValue('summary')#
</dd>
</cfif>
</dl>
</cfif>
</cfloop>
</div>
</div>
</cfoutput>
</cfsavecontent>
<cfreturn str />
</cffunction>
@kucits
Copy link

kucits commented Sep 18, 2018

Giving this another bump...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment