MACRO HELP ========== 1. PHOTO GALLERY: Point to the parent folder of more image galleries: #photoGallery('/alumni/galleries/') To specify a folder without listing parent folder: #set($folder = $render.eval('/alumni/galleries/folderName/')) #photoGallery('') To pull the most current folder according to year or use another variable: #set($dateYear = $date.get('yyyy')) #set($folder = $render.eval('/alumni/galleries/$dateYear/')) #photoGallery('') Create PhotoGallery from image fields in the structure: Import this javascrip inside into the widget or page: Now check for each image fields individually: Eg:checking image field 7, need to specify the server or ip adress #if($UtilMethods.isSet($content.picture7ImageInode) && (!$content.picture7ImageInode.trim().equals('0')) ) $!{content.Client_Name} Picture 7 #end 2. FILEREPOSITORY Get File List #fileRepository('/folder/') #foreach($file in $filesList) ${file.getExtension()} file $file.fileName $math.ceil($math.div(${file.size}, 1024)) kb $UtilMethods.dateToHTMLDate($file.publishDate,'MMM d, yyyy') $!file.friendlyName #end 3. NAVIGATION: #navigation( 1 1) ADDITIONAL OPTIONS first and last class are assignable. #set($firstItemClass = "firstItem") #set($lastItemClass = "lastItem") it also prints out with class_level# ex:
  • First Level Item
  • a prefix can be added when you have two menu's that contain the same items, that way you can have unique IDs.. #set($menuIdPrefix = "test") ex:
  • About Us
  • MenuItems Macro Check if Navigation will return >0 , then call navigation #menuItems(2 1) #if($hasItems)

    Section Overview


    #navigation(2 2) #end 4. EDIT CONTENTLET: This macro creates an edit icon with a link to edit the contentlet being pulled (such as in a loop of a pullContent). #editContentlet($contentlet.inode) 5. COMMENTS: #set($myContent = $ContentInode) #set($commentSourceCode = '/test/comments_list_only.vtl') #comment($myContent)
    #set($commentSourceCode = '/test/comments_form_only.vtl') #set($commentAutoPublish = 'true') #comment($myContent) 6. SITEMAP: pulls everything that has Show on Menu #sitemap() SiteMapFolderNL - allows to specify the starting folder the number or levels and it won't create a link to parent folders. #siteMapFolderNL(2 3 '/alumni/alumni_newsletter/') useful when wanting to create listing of pages and have the parent folder listed as well but not made into a link, specially if we dont know if this folder is going to have an index page or not.. eg. folders created by clients. Used in keystone: 7. CRUMBTRAIL: #set($crumbSeparatorImage = "/global/images/breadcrumbs_arrow.gif") #crumbtrail() USEFUL METHODS ============== isSet() Field is set #if($UtilMethods.isSet($content.variable)) .contains() - Field contains value: (use with checkboxes, radioboxes and drop down, these add a comma to the content so you can't use .equals() ) #if($content.officeOrDepartment.contains('Value')) .equals() With string values: #if($term.equals('Fall')) With variables: #if(!$dateMonth.equals($currentMonth)) Velocity Count: $velocityCount This variable is updated automatically in the for-loops, it starts with value: 1 Check if equals to value: #if($velocityCount == 1) Date Format: Month: $date.format('MMMM', $content.date)) Year: $date.format('yyyy', $content.date)) MM/DD/YYY: $date.format('MM/dd/yyyy', $content.endSeason) #set($dateYear = $date.get('yyyy')) #set($nextYear = $webapi.parseInt($dateYear) + 1) //returns current year+1 Another formatting for date: $UtilMethods.dateToHTMLDate($content.gameDatetime.toString(),'EEE MMM dd hh:mm:ss z yyyy','M/d/yyyy') Eg: 7/6/2006 $UtilMethods.dateToHTMLDate($content.gameDatetime.toString(),'EEE MMM dd hh:mm:ss z yyyy','hh:mm:ss a') Eg: 11:30 AM Empty Container #if($CONTAINER_NUM_CONTENTLETS == 0) List Size() -Can be used to determine if a pullContent query brought any results.. #pullContent.... #if($list.size() > 0) .findFolder() - Returns Folder where link was created: #if($webapi.findFolder($content.form2LinkURL)=='/about_us/departments_and_offices/forms/admissions/international/') with a variable: #set($folder='international') #if($webapi.findFolder($content.form1LinkURL)==$render.eval('/admissions/admissions_forms/$folder/')) GetContent() - used to pull content when given an Inode #getContentMapDetail($teamInode) (When using getContentMapDetail, use $content.variable ) #getContentDetail($teamInode) (When using getContentDetaik use $variable without $content.variable) Random Generator: (usually we have a query firts that pull so many items , eg: 5, the we use the generator to randomly pick one ) #set($list = $utilMethods.ramdonList($list,1)) #set($content = $list.get($math.toInteger(0))) If selecting only one random item. then we dont need to loop through the list. we can use $content.variable Replace String $string2=$string1.replaceAll("/", "//") - replaces all / with // String: Substring and Index of.. $VTLSERVLET_URI.substring(0, $VTLSERVLET_URI.indexOf('/',1)) $VTLSERVLET_URI.indexOf('/',1)) we start looking for / from the position 1 not including the character in 0 Dynamic Variables: $webapi.setVelocityVar($x, 123) Phone Formatter: $stringsapi.formatPhoneNumber('12:34-56789001') GENERAL TIPS & HELP =================== URL with absolute path: $VTLSERVLET_URI.substring(0, $VTLSERVLET_URI.lastIndexOf('/')) Page Title & Crumbtrail: #if($request.getParameter("pageTitle"))

    $request.getParameter("pageTitle")

    #else

    $!{pageTitle}

    #end
    #set($crumbSeparatorImage='/global/images/template/bullet_crumbtrail_arrow.gif') #crumbTrail()
    Pull content, then randomized it: #pullContent('+type:content +live:true +deleted:false +structureInode:70483 +languageId:1' '100' 'date1') #set($list = $UtilMethods.randomList($list,1)) #set($content = $list.get($math.toInteger(0))) Pull Relationships (the old way until david makes his macro :) #set($departmentInode = $request.getParameter('inode')) #set($relationship = $contents.getRelationshipByName('department-employee')) #set ($relatedEmployees = $contents.getRelatedContentlets($relationship.inode.toString(), $departmentInode, true)) #foreach ($employee in $relatedEmployees) #getContentMapDetail($employee.inode.toString()) $content.test
    #end Get Category: #set($inode = $request.getParameter('inode')) #getContentDetail($inode) #if($ContentletCategories.size() > 0) #set($catInode = $ContentletCategories.get(0)) Pull Link from a structure: #if($UtilMethods.isSet($content.form1LinkURL)) #if($webapi.findFolder($content.form1LinkURL)==$render.eval('/admissions/admissions_forms/$folder/')) ${content.form1LinkTitle}
    #end #end Pull with all subcategories of a main category: eg: Teams: #set($catList = $categories.getChildrenCategoriesByKey('teams')) //specify the unique key (name) of parent category, returns a list of all subcategories. #foreach($category in $catList) #set($query = "$query c${category.inode}c:on") #end #pullContent('+type:content +live:true +deleted:false +structureInode:5 +languageId:1* +($query)' '10' 'date1 desc' ) For-Loop - this works as a general for loop (for i=0; i This Section GRAB ALL OF ONE CONTENT TYPE see #pullContent macro on the edit contentlet screen of the dotCMS PULL FROM RELATIONSHIPS #set ($content = $contents.getContentByInode($request.getParameter('inode'))) #set ($relationship = $contents.getRelationshipByName("Team-News_Item")) #set ($relatedNews = $contents.getRelatedContentlets("$relationship.inode", $ContentInode, true)) #foreach ($news in $relatedNews) #getContentletDetail("$news.inode") ... #end FRAMED IMAGE #set ($frameHeight = 154) #set ($frameWidth = 120) #set($imageRatio = $math.div($ImageImageHeight, $ImageImageWidth)) #set($frameRatio = $math.div($frameHeight, $frameWidth)) image alt text DO A "One, Two, Three and Four" FORMATTED LIST #foreach ($element in $list) #if(($velocityCount!=1) && ($velocityCount=!$list.size())), #end #if($velocityCount==$list.size())and #end $element #end PARSE A VTL FILE #dotParse('/application/velocity/athletics/athletic_news_listing.vtl') Pull Date Fields, format and convert to integer and compare #set($dateMonth = $date.format('MMMM', $content.date)) #set($datePYear = $date.format('yyyy', $content.date)) #if($math.toInteger($datePYear) == $math.toInteger($dateYear)) #if(!$dateMonth.equals($currentMonth)) #set($currentMonth = $dateMonth) CONVERT DATE FIELD TO HTML DATE $webapi.dateToHTML($UtilMethods.htmlToDate($Posting_Date),'MM/dd/yy') PARSE A CONTAINER #parseContainer('comment' 'inode#') IF IN EDIT MODE #if($EDIT_MODE) in edit mode, show this #end TRUNCATE $!UtilMethods.truncatify($!Body,150) IF $FIELD IS SET #if($UtilMethods.isSet(${Body})) print this #end SUMMARY LINK TO DYNAMIC DETAIL PAGE link to detail page: Learn More in container of detail page use (only if it has 0 contentlet): -------------------------------------------------------------- #set($inode = $request.getParameter("inode")) #getContentDetail("$inode") in contentlet of detail page use: --------------------------------- #set($inode = $request.getParameter('inode')) #getContentDetail('$inode') FAKE CRUMBTITLE** link to dynamic page with fake crumbtitle: ------------------------------------------ link change pagetitle to fake crumbtrail: ------------------------------------ #set($pageTitle = $request.getParameter("crumbTitle")) #if($request.getParameter("pageTitle")) #set($pageTitle = $request.getParameter("pageTitle")) #end

    #if($crumbTitle)$crumbTitle #else $!{pageTitle} #end

    ** crumbtrail uses either crumbTitle (if crumbTitle is passed in URL), contentletTitle(if inode is passed in URL) or pageTitle ODD / EVEN ROWS start with ---------- #set($counter = 0) for each row.. -------------- #set($counter = $counter + 1) {{ in the css class put -------------------- #if($couter % 2 == 0) even #else odd #end IF THIS OR THAT.. ------------------------------------(OR)---------------------------------------- #if($UtilMethods.isSet($Box_Score) || $UtilMethods.isSet($Game_Date__Time)) do this #end THUMBNAIL GENERATOR* $Picture is whatever variable is used for the uploaded image file. ------------------------------------------------------------------ #if($UtilMethods.isSet($Picture)) #end *h=100 can be used to limit by height instead of width if both height and width are used, a background color should be specified (r=225&b=255&g=255) or else you will get a white background for the spacing around it.