Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Last active April 16, 2017 22:15
Show Gist options
  • Save stevewithington/9137544 to your computer and use it in GitHub Desktop.
Save stevewithington/9137544 to your computer and use it in GitHub Desktop.
Mura CMS : This is an example of how to dynamically populate an extended attribute select menu/selectbox based on a Mura Content Collection / Local Index.
<cfscript>
component extends="mura.cfobject" output="false" {
// Drop the methods below in your theme or site contentRenderer.cfc
// This example assumes you wish to populate the Label with the content Title, and the value stored would be the URL
// With the methods defined below, you should be able to add the following into your extended attribute fields:
// Option List: [mura]$.getSpeakersOptionList()[/mura]
// Option Label List: [mura]$.getSpeakersOptionLabelList()[/mura]
// SPEAKERS
// getSpeakersOptionList (value stored by Mura)
public any function getSpeakersOptionList() {
var it = getSpeakersfeed().getIterator();
var item = '';
var optionList = '';
While(it.hasNext()) {
item = it.next();
optionList = ListAppend(optionList, item.getURL(), '^');
};
return optionList;
}
// getSpeakersOptionLabelList (label displayed to User)
public any function getSpeakersOptionLabelList() {
var rs = getSpeakersFeed().getQuery();
return ValueList(rs.title,'^');
}
// getSpeakersFeed (assumes you have a pre-defined feed/content collection named 'Speakers')
public any function getSpeakersFeed(feedName='Speakers') {
return variables.$.getBean('feed').loadBy(name=arguments.feedName);
}
// @END Speakers
}
</cfscript>
@jobsturm
Copy link

This saved our lives! Thanks so much!

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