Pulling data from structures

Standard - By Identifier

If you want to pull all the details based on an identifier then you should use the following method:

  1. #set ($content = $dotcontent.find($identifier))  

Standard - Single

If you are trying to pull just one result then you should use the following method:

  1. #set ($newsList = $dotcontent.pull("+structureName:YOURSTRUCTURENAME +YOURSTRUCTURENAME:$identifier",1,""))  
  2. #if ($newsList.size() > 0)  
  3.     #set ($item = $newsList.get(0))  
  4.     $item.title  
  5. #end  

Standard - Multiple

The following method should be used to obtain values from the structure, especially if there is more than a single value.

You can use 0 to pull all the results HOWEVER it is much more efficient (and you should) set a limit/number. To whatever is appropriate.

  1. #set ($cont = $dotcontent.pull("+structureName:YOURSTRUCTURENAME",0,""))  
  3. #if ($cont.size() > 0)  
  4.     #foreach($con in $cont)  
  5.         $con  
  6.     #end  
  7. #end  

Pull with all subcategories of a main category: eg: Teams:

If you specify the unique key (name) of parent category, you can return a list of all subcategories.

  1. #set($catList = $categories.getChildrenCategoriesByKey('teams'))  
  2. #foreach($category in $catList)  
  3.     #set($query = "$!{query} c${category.inode}c:on")  
  4. #end  
  6. $dotcontent.pull("+type:content +live:true +deleted:false +structureInode:5* +($query)","10","" )  

Published data only

To pull only published data/live data you need to add the following +live:true to the query.

  1. #set ($cont = $dotcontent.pull("+structureName:YOURSTRUCTURENAME +live:true",0,""))  
  3. #if ($cont.size() > 0)  
  4.     #foreach($con in $cont)  
  5.           $con  
  6.     #end  
  7. #end  

Interacting with content relationships is also pretty easy with the dotcontent tool. There are 2 methods that will help. The only difference is one doesn't take a sort, or extra query conditions, and the other does. In Example 1 here we are getting the relationships for a piece of content with Identifier "asbd-asd-asda-asd" and asking for 10 of them to return. The "false" parameter is saying to get the children. If that was "true" it would pull the parents.

To specify a sort by criteria by field variable name as listed in the structures portlet, if blank it will sort by the relationship order, also the varible named is accepted to sort the results by last modified date.

Example 1:

  1. #foreach($content in $dotcontent.pullRelated("relationshipName","identifier",false,10,""))  
  2.       $content.title  
  3. #end  

In Example 2 we have added a condition and a sort. See the doc here

  1. #foreach($content in $dotcontent.pullRelated("relationshipName","identifier","+someField:someValue",false,10,""))  
  2.       $content.title  
  3. #end  

Randomise the results:

Use a standard pull to begin with, then use the generator to randomly pick one:

  1. #pullContent('+type:content +live:true +deleted:false +structureInode:70483 +languageId:1' '100' '')  
  2. #set ($list = $UtilMethods.randomList($list,1))   
  3. #set ($content = $list.get($math.toInteger(0)))  

Odd / Even rows

Great for tables/divs where you need to alternate the colour of a row - we also use jquery on the dashboard (but this works better).

  1. ##start with  
  2. #set($counter = 0)  
  4. ##for each row..  
  5. #set($counter = $counter + 1)  
  7. ##in the css class put  
  8. #if($couter % 2 == 0)  
  9.     even  
  10.     ## Of course you can put this in a table or inside the class="even"  
  11. #else  
  12.     odd  
  13.     ## class="odd"  
  14. #end  
comments powered by Disqus