Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Created September 10, 2014 00:23
Show Gist options
  • Save stevewithington/373fe25a56ee9d21be9b to your computer and use it in GitHub Desktop.
Save stevewithington/373fe25a56ee9d21be9b to your computer and use it in GitHub Desktop.
Mura CMS: How to get the primary associated image metadata such as AltText, Caption, Credits, etc.
<cfset itKids = $.content().getKidsIterator() />
<cfif itKids.hasNext()>
<ul>
<cfloop condition="itKids.hasNext()">
<li>
<cfscript>
item = itKids.next();
fileid = item.getValue('fileid');
if ( item.hasImage() ) {
fileMeta = $.getBean('fileMetaData').loadBy(fileid=item.getFileID());
WriteDump(var=fileMeta.getAllValues());
} else {
WriteOutput('This item, (#item.getTitle()#), does not have an associated image.');
}
</cfscript>
</li>
</cfloop>
</ul>
</cfif>
@AlHolden
Copy link

AlHolden commented Oct 8, 2014

How would one employ this snippet?
As a component, or embedded via [mura]$.dspInclude... it doesn't work. hasNext() returns false, even when the page has an associated image with credits.
Do we actually need to modify a display_object file in order to get image credits?

@PeterBowater
Copy link

PeterBowater commented Aug 15, 2017

@AlHolden , did you ever get anywhere with it?

<cfscript>
	fileid = $.content().getValue('fileid');

	if ( $.content().hasImage() ) {

		fileMeta = $.getBean('fileMetaData').loadBy(fileid=$.content().getFileID());

		WriteDump(var=fileMeta.getAllValues());

	 } else {

		WriteOutput('This item, (#$.content().getTitle()#), does not have an associated image.');

	}
</cfscript>

Thing is, this was written for an iterator, and not an individual content item, the above is tweaked, though untested, to operate on the current content item.

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