Back

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.

Code

## Display Content Type fields

<h2>Content</h2>

<br/><strong>Inode:</strong> $URLMapContent.inode
<br/><strong>Identifier:</strong> $URLMapContent.identifier

<br/><strong>Text Field:</strong> $URLMapContent.textField

<br/><strong>URL Title:</strong> $URLMapContent.urlTitle

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


<br/><strong>Textarea:</strong> 
<br/>$URLMapContent.textareaField

<br/><strong>WYSIWYG:</strong> 
<br/>$URLMapContent.wysiwygField

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

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

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

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


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

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


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

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

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

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


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

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

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

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

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

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

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

<br/><strong>Constant Field:</strong> $URLMapContent.constantField

<br/><strong>Custom Field:</strong> $URLMapContent.customField

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