Macros available in the dotCMS system
Macro Syntax:
#buildRSS(channelTitle channelLink channelDescription list)
Usage:
Example1: This show a simple way to call the macro with the required fields
#set($contentList = $!{contents.getEmptyList()}) #pullContent($query '0' 'modDate desc') #foreach($content in $list) #set($item = $!{contents.getEmptyMap()}) #set($_dummy = $item.put('guid', $!content.identifier)) #set($_dummy = $item.put('title', $content.title)) #set($_dummy = $item.put('description', $content.description)) #set($_dummy = $item.put('link', $!content.identifier)) #set($_dummy = $item.put('pubdate', $!content.contentLastModDate)) #set($_dummy = $!contentList.add($item)) #end #buildRSS('Channel Title','http://hostname/test/test.dot','Channel description', $contentList)
Example2: This example shows how to include one o more of the optional parameters
#set($permalinkDetailPage='123') #set($contentList = $!{contents.getEmptyList()}) #pullContent($query '0' 'modDate desc') #foreach($content in $list) #set($item = $!{contents.getEmptyMap()}) #set($_dummy = $item.put('guid', $!content.identifier)) #set($_dummy = $item.put('title', $content.titleField)) #set($_dummy = $item.put('description', $content.description)) #set($_dummy = $item.put('link', $!content.identifier)) #set($_dummy = $item.put('pubdate', $!content.contentLastModDate)) #set($_dummy = $!contentList.add($item)) #end #buildRSS('Channel Title','http://hostname/test/test.dot','Channel description', $contentList)
#buildRSSFromContent(channelTitle channelLink channelDescription query titleField descriptionField)
#buildRSSFromContent('Channel Title','http://hostname/test/test.dot','Channel description','+type:content +deleted:false +structureInode:77290 +(+languageId:1* +live:true))','test1','test6')
Example2: This example shows how to include one o more of the optional parameters.
#set($permalinkDetailPage='123') #buildRSSFromContent('Test Title','http://hostname/test/test.dot','Channel description','+type:content +deleted:false +structureInode:77290 +(+languageId:1* +live:true))','test1','test6')
comment($contentlet.inode)
Usage: Use this macro if you want to add a form to comment a contentlet, the macro, will add a form to add new comments and list the comments order by publish date.
Example 1: #set($commentForceLogin = 'false') #set($commentAutoPublish = 'true') #set($commentUseCaptcha = 'false') #set($commentStripHTML = 'false') #set($commentTitle = 'This is the question to comment') #comment($content.inode)
Example 2: This example generate a content comment and a workflow task from that comment #set($commentForceLogin = 'false') #set($commentAutoPublish = 'true') #set($commentUseCaptcha = 'false') #set($commentStripHTML = 'false')#set($commentsModeration = 'Editor')#set($commentForceLogin= 'true')#comment($content.inode)
Example 2: This example generate a content comment and a workflow task from that comment
#set($commentForceLogin = 'false') #set($commentAutoPublish = 'true') #set($commentUseCaptcha = 'false') #set($commentStripHTML = 'false')#set($commentsModeration = 'Editor')#set($commentForceLogin= 'true')#comment($content.inode)
View Tool Syntax:
$dateviewapi.friendly(date)
Usage: Use this to show the difference date and time between a string date (before the current date) and the current date.
Example 1:
Wed, 02 Apr 2008 16:23:14 +0000 #set ($tempDate = $UtilMethods.parseDate("Wed, 02 Apr 2008 16:23:14 +0000", "EEE, dd MMM yyyy HH:mm:ss +SSSS")) Result Message: $dateviewapi.friendly($tempDate)
Example 2:
Sat, 26 Apr 2008 16:23:14 +0000 #set ($tempDate = $UtilMethods.parseDate("Sat, 26 Apr 2008 16:23:14 +0000", "EEE, dd MMM yyyy HH:mm:ss +SSSS")) Result Message: $dateviewapi.friendly($tempDate)
Example 3:
Thu, 01 May 2008 16:23:14 +0000 #set ($tempDate = $UtilMethods.parseDate("Thu, 01 May 2008 16:23:14 +0000", "EEE, dd MMM yyyy HH:mm:ss +SSSS")) Result Message: $dateviewapi.friendly($tempDate)
Example 4:
Fri, 02 May 2008 14:20:00 +0000 #set ($tempDate = $UtilMethods.parseDate("Fri, 02 May 2008 14:20:00 +0000", "EEE, dd MMM yyyy HH:mm:ss +SSSS")) Result Message: $dateviewapi.friendly($tempDate)
Example 5:
Fri, 02 May 2008 17:10:00 +0000 #set ($tempDate = $UtilMethods.parseDate("Fri, 02 May 2008 17:10:00 +0000", "EEE, dd MMM yyyy HH:mm:ss +SSSS")) Result Message: $dateviewapi.friendly($tempDate)
detailPageLink($content)
Usage: Use this macro to get the detail page for a piece of content
Example 1: #set($linkTitle = 'My Title') #detailPageLink($content)
#getRating(content_identifier)
Example1:
#getRating($content.identifier)
This macro takes a list of content items, and displays them each based on the titleField and titleDescription. It rotates each piece of content and fades them out of the page to show the next one. Optional parameters can determine the fade length and colors as well as the time between each ticker display.
#ticker()
Usage: Use this macro if you want to add a content ticker to your site. You need to call the pullContent macro before calling the ticker macro, to provide the ticker with the list of content to display.
Example:
#pullContent('+type:content +deleted:false +structureInode:5 +(+languageId:1* +live:true)' '10' '') #set($titleField = 'NewsHeadline') #ticker($titleField)
Example with Optional Parameters:
#pullContent('+type:content +deleted:false +structureInode:5 +(+languageId:1* +live:true)' '10' '') #set($titleField = 'NewsHeadline') #set($descriptionField = 'NewsSummary') #set ($fadeInLenth = 500) #set ($fadeOutLenth = 500) #set ($displayLength = 2000) #set ($fgcolor = "#1A50B8") #set ($bgcolor = "#ffffff") #ticker($titleField)
<ul> <li><a href="/">Home</a></li> <li><a href="/folder_name/">Folder Name</a></li> <li>Page Name</li> <-- No Link for current page </ul>
#crumbTrail()
Usage: The crumbtrail builder will create an unordered list of links, starting from the site root or "Home Page". It will then use the folder names for folders, build the path to the current page, and then display the page title as the last link. The resulting html can be easily formatted by wrapping it in a <div> tag and assigning it appropiate css styles.
<div id="crumbtrail"> #navigation(1,1) </div>
#pullTrackbacks(identifier)
#pullTrackbacks('12345') #if($list.size() >0) #foreach($track in $list) Asset Identifier:$!{track.assetIdentifier} Title:$!{track.title} Excerpt:$!{track.excerpt} URL:$!{track.url} Blog Name:$!{track.blogName} Trackback Date:$!{track.trackDate} #end #else
<img src="/resize_image?[[path] or [inode]] &[ [[height] and/or [width]] or [[maxh] and [maxw]] ]">
Usage: The use of this servlet is very easy. You only have to add in the src attribute of the html image tag, the following text < img src="/resize_image?<parameters> " >
<img src="/resize_image?path=/images/image.jpg&maxw=120&maxh=130"> <img src="/resize_image?inode=91&maxw=120&maxh=130"> <img src="/resize_image?path=/images/image.jpg&w=80&h=80"> <img src="/resize_image?inode=91&w=80&h=80"> <img src="/resize_image?path=/images/image.jpg&w=80"> <img src="/resize_image?inode=91&w=80"> <img src="/resize_image?path=/images/image.jpg&h=80"> <img src="/resize_image?inode=91&h=80">
<img src="/thumbnail?inode=[inode]&[ [[height] and/or [width]] or [[r] and [g] and [b]] ]">
Usage: The use of this servlet is very easy. You only have to add in the src attribute of the html image tag, the following text < img src="/thumbnail?<parameters> " >
<img src="/thumbnail?inode=91&w=120&h=130"> <img src="/thumbnail?inode=91&w=120"> <img src="/thumbnail?inode=91&h=130"> <img src="/thumbnail?inode=91&w=120&h=130&r=200&g=100&b=50">
#decrypt('string to decrypt')
#encrypt('website@dotcms.org') #decrypt($encryptedStr) This is the decrypted value = $decryptedStr
#encrypt('string to encrypt')
#encrypt('website@dotcms.org') #set ($to = $encryptedStr)
#events('from' 'to')
#events('1/1/2006' '2/1/2006')
#getSQLResults('select * from table')
Usage: Use this macro if you want to pull data from a database and display the results within some piece of content. If the SQL throws an error it will store the error in a variable named SQLError. See the example below for instructions on how to use this. It is only optional that you check for the error but it is recommended that you do so that your sql won't fail silently.
#set ($dbConnection = 'jdbc/test1') #set ($dbStartRow = 1) #set ($dbMaxRow = 4) #getSQLResults('select * from test order by id') $SQLError #foreach($r in $results) $r.id #end
Example 2 - Here you see the the error being checked for and a custom message being throw on error:
#set ($dbConnection = 'jdbc/test1') #set ($dbStartRow = 1) #set ($dbMaxRow = 4) #getSQLResults('select * from test order by id') #if($SQLError) Custom SQL message - I Failed #else #foreach($r in $results) $r.id #end #end
#fileRepository('path')
Usage: The repository will show a list of files and folders that the view user has permissions to view. If the user is not logged in, they will only be able to view files and folders that have the CMS_ANONYMOUS read permission. If the user is logged in, they will be able to view any files and folders they have read permission on.
#fileRepository('/resources/documentation')
#set($fileRepositorySourceCode = '/application/file_repository.vtl') #fileRepository('/documentation/repository') And the /application/file_repository file could look like this #foreach($file in $fileRepository_filesList) #set($imgpath = "/resize_image?path=/dotAsset/${file.identifier}.${file.getExtension()}&w=178") #end
#getContent(contentIdentifier)
#set($id = $request.getParameter("id")) #if($id) #getContent($id) #end My title is $content.title
$googleapi.searchGoogleMini(client, collection, subcollection, query, metaquery, start, num, autoFilter)
Usage: Use this to pull search results from a google mini appliance, to make this web api work you have to setup the variable GOOGLE_MINI_SEARCH_URL on the dotmarketing.config.properties file pointing to the google mini appliance url like GOOGLE_MINI_SEARCH_URL=http://googlemini.dotcms.org The api returns an specific GoogleMiniSearch object that contains all the variables necessary to display all the retrieved results. GoogleMiniSearch Object - Attributes
searchTime - The time taken by the appliance to retrieve the results query - The request query fromIndex - The start index of results toIndex - The end index of retrieved results estimatedTotal - The estimated total of result based on the given query searchResults - The list of results, this is a list of GoogleMiniSearchResult objects hasNextPage() - Method that returns true if results has a next page to display hasPreviousPage() - Method that returns true if results has a previous page to display
identationLevel - Level of indentation used for inner results mimeType - Mime type of the result resultURL - The url to the result title - The title generalRatingRelevance - Relevance of the document in google mini additionalSearchDetails - More details about the retrived document snippet - Result snippet metaTagsFields - A map of metatags associated to the result
#set($searchObj = $googleapi.searchGoogleMini("default_frontend", "Main_Site", "", "Knight", "", 0, 100, false)) Search Summary Total Search time: $searchObj.searchTime Query: $searchObj.query From Index: $searchObj.fromIndex To Index: $searchObj.toIndex Estimated Total: $searchObj.estimatedTotal Has Next Results Page: $searchObj.hasNextPage() Has Previous Results Page: $searchObj.hasPreviousPage() Estimated Total of Results: $searchObj.estimatedTotal #foreach($result in $searchObj.searchResults) Result Index: $result.resultIndex Identation Level: $result.identationLevel Title: $result.title Snippet: $result.snippet Result URL: $result.resultURL General Rating Relevance: $result.generalRatingRelevance Mime Type: $result.mimeType Additional Search Details: $result.additionalSearchDetails Meta Tags Fields: $result.metaTagsFields #end
#getFilesFromFS('path')
Usage: The repository will show a list of files in a folder on the underlying file system. WARNING: THIS MACRO BYPASSES THE CMS PERMISSIONS COMPLETELY.
#getFilesFromFS('/css') #foreach($file in $files) title: $!file.name size : $!file.size prettySize : $!file.prettySize date : $!file.date prettyDate : $!file.prettyDate link: $!file.link #end
#mailingList()
Example1: Let's assume we have a page with this macro, let's call it mailinglists_subscription.dot, if the user is logged in, this page can be accessed directly and its content will have the following macro call
#mailingLists()
Example2: The user is not logged in, but we can access the prior page passing through the respective encrypted userId using the respective request parameter
mailinglists_subscription.dot?ui=UUZVXTMAEvP6ABUja7Rkhg==
#mp3Player('path')
#mp3Player('/path/to/mp3s/file.mp3')
#mp3Player('/path/to/mp3s/playlist.xml')
#mp3PlayerButton('song_url')
#mp3PlayerButton('/path/to/mp3s/example.mp3')
#mp3PlayerButton('/path/to/playlist.xml')
#mp3PlayerExtended('song_url')
#mp3PlayerExtended('/path/to/mp3s/example.mp3')
<ul> <li><a href="/path/to/pageOrFolder">Menu item 1</a></li> <li class="active"><a href="/path/to/pageOrFolder">Menu item 2</a></li> <li><a href="/path/to/pageOrFolder">Menu item 3</a></li> </ul>
#navigation('startLevel' 'levelsToShow')
Syntax:
<div id="topNav"> #navigation(1,1) </div>
<div id="leftNav"> #navigation(2,2) </div>
<div id="leftNav"> #set($menuSpans = true) #navigation(2,2) </div>
<div id="leftNav"> #set($openAllLevels=true) #navigation(2,2) </div>
#pageContent('query' 'sort by' '# per page' '# current page')
#pageContent('+type:content +live:true +structureInode:5' 'date1' '5' '1') #foreach($content in $list) title: $!content.contentTitle summary: $!content.NewsSummary #end
#permalink(identifier)
#permalink('12345')
Example2:
#set($permalinkDetailPage='78945') #permalink('12345')
Example3:
#set($permalinkTitle ="The Title") #permalink('12345')
#trackback(identifier)
#trackback('12345')
#photoCarrousel (photoList photoDimensions)
Example 1: This show a simple way to call the macro setting the image folder
#set($imageFolder = '/global/images/screencaps/') #set($photoDimensions = $contents.getEmptyMap()) #set($dummy = $!photoDimensions.put("width", "125")) #set($dummy = $!photoDimensions.put("height", "125")) #set($photoCarrouselAutoSlide = true) #set($photoList = $contents.getEmptyList()) #photoCarrousel($photoList $photoDimensions)
Example 2: This show a simple way to call the macro with the photo list fields
#set($photoList = $contents.getEmptyList()) #set($photo = $contents.getEmptyMap()) #set($dummy = $!photo.put("url", "/html/1.jpg")) #set($dummy = $!photo.put("link", "http://www.yahoo.com")) #set($dummy = $!photoList.add($photo)) #set($photo = $contents.getEmptyMap()) #set($dummy = $!photo.put("url", "/html/2.jpg")) #set($dummy = $!photo.put("link", "http://www.google.com")) #set($dummy = $!photoList.add($photo)) #set($photo = $contents.getEmptyMap()) #set($dummy = $!photo.put("url", "/html/3.jpg")) #set($dummy = $!photo.put("link", "http://www.dotcms.org")) #set($dummy = $!photoList.add($photo)) #set($photo = $contents.getEmptyMap()) #set($dummy = $!photo.put("url", "/html/4.jpg")) #set($dummy = $!photo.put("link", "http://www.hotmail.com")) #set($dummy = $!photoList.add($photo)) #set($photoDimensions = $contents.getEmptyMap()) #set($dummy = $!photoDimensions.put("width", "125")) #set($dummy = $!photoDimensions.put("height", "125")) #set($photoCarrouselAutoSlide = true) #photoCarrousel($photoList $photoDimensions)
#photoGallery('/thefolder')
#photoGallery('/photo_galleries')
#printAverageRating(content_identifier)
#printAverageRating($content.identifier)
#printNumberOfVotes(content_identifier)
#printNumberOfVotes($content.identifier)
#pullRSS('url')
#set($rssFilter = ['dotcms','dotmarketing'])#set($rssTotal = 10)#pullRSS('http://somesite/topnews.rss')#foreach($content in $list) title: $!content.title description: $!content.description#end
#pullContent('query' '# results' 'sort by')
#pullContent('+type:content +live:true +structureInode:5' '5' 'date1')#foreach($content in $list) title: $!content.contentTitle summary: $!content.NewsSummary#end
#pullRelatedContent('relationship name' 'content inode' 'limit' 'sort by')
#pullRelatedContent('Annual_Report_Article-Audio' '4686' '100' 'fullHeadline asc, bodyText desc, modDate') #foreach($content in $list) headline: $!content.fullHeadline body: $!content.bodyText#end
#randomImage (path)
#set ($path = '/global/images/') #randomImage($path) <img src="/resize_image?inode=$!{image.inode}&w=911&h=322" alt="Top Banner" width="911" height="322" />
#selectedInode()
#sendtofriend (articleText)
Example1: This shows a simple way to call the macro with the required fields
#set($sendToFriendStyle = "display:inline;") #sendtofriend('This is a Send To Friend test!!!')
#sitemap()
Usage: Use this macro if you want to add a site map for your whole site.
#siteMapFolder(2,2,'/folder1/myFolder')
Usage: Use this macro if you want to add a site map to your page from a specific path. You can specify how many level from the path to start and end.
#set($reverseOrder = true) #siteMapFolder(2,2,'/folder1/myFolder')
#set($showHome = true) #siteMapFolder(2,2,'/folder1/myFolder')
#socialBookmarks()
#set ($socialBookmarksList = ['digg','delicious','yahoo','google','newsvine'])
#tagCloud(structureNames url maxNumberOfTags)
#tagCloud(["White Papers", "Blogs", "Testimonial"] '/mypage.dot' 40)
#set($ignoredTags = ["tag1", "tag2"])
#textArea(name style)
#textArea($myName "width:200px")
#set($id = "myID")
#set($value = $myValue)
#textArea("myName" "width:200px")
#titleImage('title')
#set ($font = 'tahoma') #set ($size = '20') #set ($color = '30,30,30') #titleImage('Test Title')
#videoGallery(url)
#videoGallery('/videos/')
#set($showVideoTitle = false) #set($showVideoDescription = false) #videoGallery('/videos/')
#set($w = 200) #set($h = 200) #videoGallery('/videos/')
Example4:
#set($galleriesToShow = 2) #videoGallery('/videos/')
#videoPlayer(url)
#videoPlayer('/global/videos/myvideo.flv')
#set($width = '500') #set($height = '500') #set($autoPlay = 'true') #set($backgroundColor = '#000000') #set($scale = 'default') #videoPlayer('/global/videos/myvideo.flv')