How to Display Content Type's Fields

Description

On this example we will show how to use Velocity to display the values for each type of field on a content type.

We created a new structure and added one of each type of field and grouped them using tab dividers.

Then created a Widget that displays all the possible values for each field type.

Image

How to Display Content Type's Fields

Code

<h2>Content</h2>

<br/><strong>Inode:</strong> ${esc.d}URLMapContent.inode
<br/><strong>Identifier:</strong> ${esc.d}URLMapContent.identifier

<br/><strong>Text Field:</strong> ${esc.d}URLMapContent.textField

<br/><strong>URL Title:</strong> ${esc.d}URLMapContent.urlTitle

<br/><strong>Host or Folder Field:</strong> 
<br/>${esc.d}URLMapContent.hostOrFolderField.name, ${esc.d}URLMapContent.hostOrFolderField.title, ${esc.d}URLMapContent.hostOrFolderField.identifier


<br/><strong>Textarea:</strong> 
<br/>${esc.d}URLMapContent.textareaField

<br/><strong>WYSIWYG:</strong> 
<br/>${esc.d}URLMapContent.wysiwygField

<p><h2>Date and Times</h2></p>

<br/><strong>Date:</strong> ${esc.d}URLMapContent.dateField --> ${esc.d}date.format("MM/dd/yyyy",${esc.d}URLMapContent.dateField)

<br/><strong>Date and Time:</strong> ${esc.d}URLMapContent.dateAndTimeField --> ${esc.d}date.format("MM/dd/yyyy hh:mm:ss z",${esc.d}URLMapContent.dateAndTimeField)

<br/><strong>Time:</strong> ${esc.d}URLMapContent.timeField --> ${esc.d}date.format("hh:mm:ss z",${esc.d}URLMapContent.timeField)


<p><h2>Images and Files</h2></p>

<br/><strong>Binary Image:</strong> 
<strong>Resize Image</strong>
<p><img src="/contentAsset/image/${esc.d}URLMapContent.identifier/binaryImage/filter/Resize/resize_w/500"></p>
<br/><strong>Thumbnail Image</strong>
<p><img src="/contentAsset/image/${esc.d}URLMapContent.identifier/binaryImage/filter/Thumbnail/thumbnail_w/200/thumbnail_h/200/thumbnail_bg/000000000"></p>


<br/><strong>File Field:</strong> 

<br/>File metaData: ${esc.d}URLMapContent.fileField.metaData
${esc.h}foreach(${esc.d}md in ${esc.d}URLMapContent.fileField.metaData) ${esc.d}md.key : ${esc.d}md.value, ${esc.h}end
<br/>File uri: ${esc.d}URLMapContent.fileField.uri
<br/>File inode: ${esc.d}URLMapContent.fileField.map.inode
<br/>File identifier: ${esc.d}URLMapContent.fileField.map.identifier
<br/>File size: ${esc.d}URLMapContent.fileField.fileSize
<br/>File mimeType: ${esc.d}URLMapContent.fileField.mimeType
<br/>File extension: ${esc.d}URLMapContent.fileField.extension

<br/><strong>Image Field:</strong>

<br/>Image metaData: ${esc.d}URLMapContent.imageField.metaData
<br/>Image uri: ${esc.d}URLMapContent.imageField.uri
<br/>Image path: ${esc.d}URLMapContent.imageField.path
<br/>Image inode: ${esc.d}URLMapContent.imageField.map.inode
<br/>Image identifier: ${esc.d}URLMapContent.imageField.map.identifier
<br/>Image size: ${esc.d}URLMapContent.imageField.fileSize
<br/>Image height: ${esc.d}URLMapContent.imageField.height
<br/>Image width: ${esc.d}URLMapContent.imageField.width
<br/>Image mimeType: ${esc.d}URLMapContent.imageField.mimeType
<br/>Image extension: ${esc.d}URLMapContent.imageField.extension
<br/>Resized image: <img src="/contentAsset/image/${esc.d}URLMapContent.imageField.map.identifier/fileAsset/filter/Resize/resize_w/500">


<p><h2>Multiple Values</h2></p>

<p><strong>Checkbox Field:</strong> 
<br/>Options: ${esc.d}URLMapContent.checkboxField.options
<br/>values: ${esc.d}URLMapContent.checkboxField.values
<br/>Selected Values: ${esc.h}foreach(${esc.d}value in ${esc.d}URLMapContent.checkboxField.selectedValues) ${esc.d}value, ${esc.h}end
</p>

<p><strong>Multi Select Field:</strong> 
<br/>Options: 
${esc.h}foreach(${esc.d}option in ${esc.d}URLMapContent.multiSelectField.options) ${esc.d}option, ${esc.h}end
<br/>values: ${esc.d}URLMapContent.multiSelectField.values
<br/>Selected Values: ${esc.h}foreach(${esc.d}value in ${esc.d}URLMapContent.multiSelectField.selectedValues) ${esc.d}value, ${esc.h}end
</p>

<p><strong>Radio Field:</strong> 
<br/>Options: 
${esc.h}foreach(${esc.d}option in ${esc.d}URLMapContent.radioField.options) ${esc.d}option, ${esc.h}end
<br/>values: ${esc.d}URLMapContent.radioField.values
<br/>Selected Values: ${esc.d}URLMapContent.radioField.selectValue
</p>

<p><strong>Select Field:</strong> 
<br/>Options: 
${esc.h}foreach(${esc.d}option in ${esc.d}URLMapContent.selectField.options) ${esc.d}option, ${esc.h}end
<br/>values: ${esc.d}URLMapContent.selectField.values
<br/>Selected Values:  ${esc.d}URLMapContent.selectField.selectValue
</p>
<h2>Taxonomy</h2>

<br/><strong>Category Field:</strong>
${esc.h}foreach(${esc.d}category in ${esc.d}URLMapContent.categoryField)
<br/>${esc.d}category.categoryName, ${esc.d}category.key
${esc.h}end
<br/><strong>Tags Field:</strong> 
${esc.h}foreach(${esc.d}tag in ${esc.d}URLMapContent.tagField) ${esc.d}tag, ${esc.h}end

<p><h2>Other</h2></p>

<br/><strong>Constant Field:</strong> ${esc.d}URLMapContent.constantField

<br/><strong>Custom Field:</strong> ${esc.d}URLMapContent.customField

<br/><strong>Key/Value Field:</strong> 
${esc.h}if (${esc.d}UtilMethods.isSet(${esc.d}URLMapContent.keyValueField))
		  ${esc.h}foreach(${esc.d}key in ${esc.d}URLMapContent.keyValueField.entrySet())
			  ${esc.h}if(${esc.d}key.key != "map" && ${esc.d}key.key != "keys")
				${esc.d}key.key: ${esc.d}key.value
			  ${esc.h}end
		  ${esc.h}end
${esc.h}end