stephenjbell

Dynamic Strings - dotCMS

Jul 13th, 2011
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.79 KB | None | 0 0
  1. ## Use your own syntax in strings to create complex logic
  2.  
  3. #set($myString="Arts course: ^^ARTS-2113^^, Biology course: ^^BIOL-1244^^")
  4. <p>
  5. <h2>Starting string</h2>
  6. $myString
  7. </p>
  8.  
  9. <p>
  10. <h2>Simple regex replace:</h2>
  11. $myString.replaceAll("\^\^([A-Z]{4})-?([0-9]{4})\^\^","$2 $1")
  12. </p>
  13.  
  14. <p>
  15. <h2>Use sections of string to perform pulls</h2>
  16. #set($stringPieces = $myString.split("\^\^"))
  17.  
  18. #set($stringPieceCount = 0)
  19. #foreach($stringPiece in $stringPieces)
  20.     #if($stringPiece.matches("([A-Z]{4})-?([0-9]{4})"))
  21.         #set($startLetters = $stringPiece.substring(0,3))
  22.         #foreach($story in $dotcontent.pull("+structureName:OcNews +OcNews.title:${startLetters}*",1,"modDate desc"))
  23.             $story.title
  24.         #end
  25.     #else
  26.         $stringPiece
  27.     #end
  28.     #set($stringPieceCount = $stringPieceCount + 1)
  29. #end
  30. </p>
Advertisement
Add Comment
Please, Sign In to add comment