SlideShare a Scribd company logo
1 of 16
Download to read offline
Velocity	
  Tips	
  and	
  Tricks	
  	
  

      Simple	
  Solu5ons	
  to	
  
      Common	
  Problems	
  
      Wed.,	
  April	
  14,	
  2010	
  
Velocity	
  ABC	
  
•  Variables:	
  
   –  #set($thumbWidth	
  =	
  55)	
  
   –  #set($varString	
  =	
  ‘ The	
  width	
  is‘)	
  
   –  #set($varString	
  =	
  “${varString}	
  ${thumbWidth}	
  px“)	
  
•  Proper5es:	
  
   –  $news.shortSummary	
  
   –  $news.expireDate	
  
•  Methods:	
  
   –  #set($_today	
  =	
  $date.getDate())	
  
   –  #set($_todayFormated	
  =	
  $date.format('yyyyMMddHHmmss',
      $_today))	
  
Velocity	
  ABC	
  
•  If	
  /	
  ElseIf	
  /	
  Else	
  statements	
  
#if($condi5on_1)	
  
	
  	
  	
  	
  Condi5on	
  1	
  was	
  met	
  
#elseif($condi5on_2)	
  
	
  	
  	
  	
  Condi5on	
  2	
  was	
  met	
  
#else	
  
	
  	
  	
  	
  	
  Another	
  condi5on	
  was	
  met	
  
#end	
  


•  AND	
  /	
  OR	
  	
  
#if($condi5on_1	
  &&	
  $condi5on_2)	
  	
  …	
  	
  #end	
  
#if($condi5on_1	
  ||	
  $condi5on_2)	
  	
  …	
  #end	
  
Velocity	
  ABC	
  
•  Lists	
  
#set($mylist	
  =	
  [])	
  
$mylist.add("asd")	
  
$mylist.add(123)	
  
$mylist.get(0)	
  

•  Maps	
  
#set($contentList	
  =	
  $!{contents.getEmptyList()})	
  	
  
#set($item	
  =	
  $!{contents.getEmptyMap()})	
  	
  
#set($_dummy	
  =	
  $item.put('guid',	
  $!content.get('iden5fier')))	
  	
  
#set($_dummy	
  =	
  $item.put('5tle',	
  $content.get($5tleField)))	
  
#set($_dummy	
  =	
  $!contentList.add($item))	
  	
  
Velocity	
  ABC	
  
•  Lists	
  and	
  Foreach	
  	
  
#foreach($item	
  in	
  $myList)	
  
	
  	
  	
  $item.5tle	
  <br/>	
  	
  
#end	
  


•  Velocity	
  Comments	
  
##	
  Commen5ng	
  one	
  line	
  
#*	
  	
  	
  Commen5ng	
  
	
  	
  	
  	
  	
  	
  	
  Mul5ple	
  lines	
  

*#	
  
Velocity	
  and	
  dotCMS	
  
•  Useful	
  variables:	
  
   –  $EDIT_MODE	
  
   –  $CONTAINER_NUM_CONTENTLETS	
  
   –  $VTLSERVLET_URI	
  
Velocity	
  and	
  dotCMS	
  
•  View	
  Tools	
  are	
  configured	
  in:	
  
    –  dotCMSWEB-­‐INFtoolbox.xml	
  


•  Three	
  types	
  of	
  view	
  tools:	
  
    –  Velocity	
  view	
  tools:	
  org.apache.velocity.tools….	
  
    –  dotCMS	
  view	
  tools:	
  
       com.dotmarke5ng.viewtools….	
  
    –  Customized	
  view	
  tools:	
  plugins	
  
Velocity	
  and	
  dotCMS	
  

•  Velocity	
  View	
  Tool	
  
   samples:	
  

    –  MathTool	
  
    –  ListTool	
  
    –  DateTool	
  



  hpp://velocity.apache.org/tools/devel/javadoc/   	
  
Velocity	
  and	
  dotCMS	
  
•  dotCMS	
  View	
  Tool	
  
   samples:	
  
    –  CategoriesWebAPI	
  
    –  WebAPI	
  
    –  ContentsWebAPI	
  




  hpp://www.dotcms.org/api/     	
  
Velocity	
  and	
  dotCMS	
  
•  org.apache.velocity.tools.generic.MathTool:	
  
   –  java.lang.Number	
  add(java.lang.Object	
  num1,	
  
      java.lang.Object	
  num2)	
  
   –  java.lang.Number	
  div(java.lang.Object	
  num1,	
  
      java.lang.Object	
  num2)	
  
   –  java.lang.Double	
  getRandom()	
  
   –  java.lang.Number	
  max(java.lang.Object	
  num1,	
  
      java.lang.Object	
  num2)	
  
   –  java.lang.Number	
  sub(java.lang.Object	
  num1,	
  
      java.lang.Object	
  num2)	
  	
  
Velocity	
  and	
  dotCMS	
  
•  org.apache.velocity.tools.generic.ListTool:	
  
   –  java.lang.Boolean	
  contains(java.lang.Object	
  list,	
  
      java.lang.Object	
  element)	
  	
  
   –  java.lang.Object	
  get(java.lang.Object	
  list,	
  int	
  index)	
  	
  
   –  java.lang.Boolean	
  isEmpty(java.lang.Object	
  list)	
  	
  
   –  java.lang.Integer	
  size(java.lang.Object	
  list)	
  	
  
Velocity	
  and	
  dotCMS	
  
•  org.apache.velocity.tools.generic.DateTool:	
  
   –  java.u5l.Date	
  getDate()	
  
   –  java.lang.Integer	
  getDay(java.lang.Object	
  date)	
  
   –  java.lang.Integer	
  getMonth(java.lang.Object	
  date)	
  
   –  sta5c	
  java.u5l.Date	
  getSystemDate()	
  
   –  java.lang.Integer	
  getYear(java.lang.Object	
  date)	
  
   –  java.u5l.Date	
  toDate(java.lang.Object	
  obj)	
  
   –  java.lang.String	
  toString()	
  
Velocity	
  and	
  dotCMS	
  
•  CategoriesWebAPI:	
  
   –  List<Category>	
  getChildrenCategoriesByKey(String	
  
      key)	
  
   –  Category	
  getCategoryByKey(String	
  key)	
  
   –  Category	
  getCategoryByName(String	
  name)	
  
   –  List<Category>	
  getChildrenCategories(Category	
  cat)	
  
   –  List<Category>	
  getChildrenCategories(Inode	
  inode)	
  
   –  List<Category>	
  getChildrenCategories(String	
  inode)	
  
   –  String	
  getCategoryKeyByContentlet(String	
  
      contentletInode)	
  
Velocity	
  and	
  dotCMS	
  
•  WebAPI:	
  
   –  int	
  parseInt(String	
  num)	
  
   –  int	
  parseInt(int	
  num)	
  
   –  String	
  toString(long	
  num)	
  
   –  boolean	
  isSet(String	
  input)	
  
   –  List<String>	
  splitString(String	
  str,	
  String	
  sep)	
  
   –  String	
  encodeURL(String	
  url)	
  
   –  List<Contentlet>	
  getContentletsByCategory(String	
  
      catInode)	
  
   –  	
  String	
  getContentIden5fier(String	
  parsePath)	
  
   –  String	
  getUserFullName()	
  
Velocity	
  and	
  dotCMS	
  
•  ContentsWebAPI:	
  
   –  Contentlet	
  getContentByInode(String	
  inode)	
  
   –  Structure	
  getStructureByType(String	
  structureType)	
  
   –  Structure	
  getStructureByInode(String	
  structureInode)	
  
   –  Field	
  getFieldByName(Structure	
  st,	
  String	
  fieldName)	
  
   –  List<Contentlet>	
  getContents(String	
  structureType,	
  
      String	
  categoryName)	
  
   –  List<Category>	
  getContentletCategories(String	
  inode)	
  	
  
   –  List	
  getEmptyList()	
  
Examples	
  
•    Dynamic	
  Banner	
  
•    Category	
  Example	
  
•    News	
  Pull	
  
•    Simple	
  Year	
  Archive	
  

More Related Content

Similar to Velocity tips and tricks

Schema Design by Chad Tindel, Solution Architect, 10gen
Schema Design  by Chad Tindel, Solution Architect, 10genSchema Design  by Chad Tindel, Solution Architect, 10gen
Schema Design by Chad Tindel, Solution Architect, 10genMongoDB
 
第49回Php勉強会@関東 Datasource
第49回Php勉強会@関東 Datasource第49回Php勉強会@関東 Datasource
第49回Php勉強会@関東 DatasourceKaz Watanabe
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)Doris Chen
 
Collections Framework Beginners Guide 2
Collections Framework Beginners Guide 2Collections Framework Beginners Guide 2
Collections Framework Beginners Guide 2Kenji HASUNUMA
 
Collections Framework Begineers guide 2
Collections Framework Begineers guide 2Collections Framework Begineers guide 2
Collections Framework Begineers guide 2Kenji HASUNUMA
 
iPhone Development Intro
iPhone Development IntroiPhone Development Intro
iPhone Development IntroLuis Azevedo
 
Introductionto fp with groovy
Introductionto fp with groovyIntroductionto fp with groovy
Introductionto fp with groovyIsuru Samaraweera
 
Fazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchFazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchPedro Franceschi
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao IntroductionBooch Lin
 
Iniciando com jquery
Iniciando com jqueryIniciando com jquery
Iniciando com jqueryDanilo Sousa
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup PerformanceJustin Cataldo
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talkdtdannen
 
Amazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersAmazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersJeremy Lindblom
 
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
Business Dashboards using Bonobo ETL, Grafana and Apache AirflowBusiness Dashboards using Bonobo ETL, Grafana and Apache Airflow
Business Dashboards using Bonobo ETL, Grafana and Apache AirflowRomain Dorgueil
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejsNick Lee
 

Similar to Velocity tips and tricks (20)

Learning How To Use Jquery #3
Learning How To Use Jquery #3Learning How To Use Jquery #3
Learning How To Use Jquery #3
 
Schema Design by Chad Tindel, Solution Architect, 10gen
Schema Design  by Chad Tindel, Solution Architect, 10genSchema Design  by Chad Tindel, Solution Architect, 10gen
Schema Design by Chad Tindel, Solution Architect, 10gen
 
第49回Php勉強会@関東 Datasource
第49回Php勉強会@関東 Datasource第49回Php勉強会@関東 Datasource
第49回Php勉強会@関東 Datasource
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
Super spike
Super spikeSuper spike
Super spike
 
Collections Framework Beginners Guide 2
Collections Framework Beginners Guide 2Collections Framework Beginners Guide 2
Collections Framework Beginners Guide 2
 
Collections Framework Begineers guide 2
Collections Framework Begineers guide 2Collections Framework Begineers guide 2
Collections Framework Begineers guide 2
 
iPhone Development Intro
iPhone Development IntroiPhone Development Intro
iPhone Development Intro
 
Introductionto fp with groovy
Introductionto fp with groovyIntroductionto fp with groovy
Introductionto fp with groovy
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Fazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchFazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearch
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
 
Iniciando com jquery
Iniciando com jqueryIniciando com jquery
Iniciando com jquery
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Jquery
JqueryJquery
Jquery
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talk
 
Amazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersAmazon Web Services for PHP Developers
Amazon Web Services for PHP Developers
 
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
Business Dashboards using Bonobo ETL, Grafana and Apache AirflowBusiness Dashboards using Bonobo ETL, Grafana and Apache Airflow
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 

More from dotCMS

Unleash Your Content: Content-as-a-Service
Unleash Your Content: Content-as-a-ServiceUnleash Your Content: Content-as-a-Service
Unleash Your Content: Content-as-a-ServicedotCMS
 
How Does an Organization Manage Hundreds of Sites?
How Does an Organization Manage Hundreds of Sites?How Does an Organization Manage Hundreds of Sites?
How Does an Organization Manage Hundreds of Sites?dotCMS
 
The Making of a Rockin' Web Team
The Making of a Rockin' Web TeamThe Making of a Rockin' Web Team
The Making of a Rockin' Web TeamdotCMS
 
Justifying IT Spending
Justifying IT SpendingJustifying IT Spending
Justifying IT SpendingdotCMS
 
Aligning Your Web Initiative with Your Business
Aligning Your Web Initiative with Your BusinessAligning Your Web Initiative with Your Business
Aligning Your Web Initiative with Your BusinessdotCMS
 
dotCMS Roadmap 2010
dotCMS Roadmap 2010dotCMS Roadmap 2010
dotCMS Roadmap 2010dotCMS
 
Plugin Overview I and II
Plugin Overview I and IIPlugin Overview I and II
Plugin Overview I and IIdotCMS
 
Migrating to v1.9
Migrating to v1.9Migrating to v1.9
Migrating to v1.9dotCMS
 
Going Multi-Tenant with dotCMS
Going Multi-Tenant with dotCMSGoing Multi-Tenant with dotCMS
Going Multi-Tenant with dotCMSdotCMS
 
Building Mobile Apps and Sites in dotCMS
Building Mobile Apps and Sites in dotCMSBuilding Mobile Apps and Sites in dotCMS
Building Mobile Apps and Sites in dotCMSdotCMS
 
Super widget
Super widgetSuper widget
Super widgetdotCMS
 
SEO and search plugins
SEO and search pluginsSEO and search plugins
SEO and search pluginsdotCMS
 
Out ofmemory
Out ofmemoryOut ofmemory
Out ofmemorydotCMS
 
Host and Permissions in v1.9
Host and Permissions in v1.9 Host and Permissions in v1.9
Host and Permissions in v1.9 dotCMS
 
Forms as Structured Content
Forms as Structured Content Forms as Structured Content
Forms as Structured Content dotCMS
 
Categories vs relationships
Categories vs relationshipsCategories vs relationships
Categories vs relationshipsdotCMS
 

More from dotCMS (17)

Unleash Your Content: Content-as-a-Service
Unleash Your Content: Content-as-a-ServiceUnleash Your Content: Content-as-a-Service
Unleash Your Content: Content-as-a-Service
 
How Does an Organization Manage Hundreds of Sites?
How Does an Organization Manage Hundreds of Sites?How Does an Organization Manage Hundreds of Sites?
How Does an Organization Manage Hundreds of Sites?
 
SEO
SEO SEO
SEO
 
The Making of a Rockin' Web Team
The Making of a Rockin' Web TeamThe Making of a Rockin' Web Team
The Making of a Rockin' Web Team
 
Justifying IT Spending
Justifying IT SpendingJustifying IT Spending
Justifying IT Spending
 
Aligning Your Web Initiative with Your Business
Aligning Your Web Initiative with Your BusinessAligning Your Web Initiative with Your Business
Aligning Your Web Initiative with Your Business
 
dotCMS Roadmap 2010
dotCMS Roadmap 2010dotCMS Roadmap 2010
dotCMS Roadmap 2010
 
Plugin Overview I and II
Plugin Overview I and IIPlugin Overview I and II
Plugin Overview I and II
 
Migrating to v1.9
Migrating to v1.9Migrating to v1.9
Migrating to v1.9
 
Going Multi-Tenant with dotCMS
Going Multi-Tenant with dotCMSGoing Multi-Tenant with dotCMS
Going Multi-Tenant with dotCMS
 
Building Mobile Apps and Sites in dotCMS
Building Mobile Apps and Sites in dotCMSBuilding Mobile Apps and Sites in dotCMS
Building Mobile Apps and Sites in dotCMS
 
Super widget
Super widgetSuper widget
Super widget
 
SEO and search plugins
SEO and search pluginsSEO and search plugins
SEO and search plugins
 
Out ofmemory
Out ofmemoryOut ofmemory
Out ofmemory
 
Host and Permissions in v1.9
Host and Permissions in v1.9 Host and Permissions in v1.9
Host and Permissions in v1.9
 
Forms as Structured Content
Forms as Structured Content Forms as Structured Content
Forms as Structured Content
 
Categories vs relationships
Categories vs relationshipsCategories vs relationships
Categories vs relationships
 

Recently uploaded

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Recently uploaded (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Velocity tips and tricks

  • 1. Velocity  Tips  and  Tricks     Simple  Solu5ons  to   Common  Problems   Wed.,  April  14,  2010  
  • 2. Velocity  ABC   •  Variables:   –  #set($thumbWidth  =  55)   –  #set($varString  =  ‘ The  width  is‘)   –  #set($varString  =  “${varString}  ${thumbWidth}  px“)   •  Proper5es:   –  $news.shortSummary   –  $news.expireDate   •  Methods:   –  #set($_today  =  $date.getDate())   –  #set($_todayFormated  =  $date.format('yyyyMMddHHmmss', $_today))  
  • 3. Velocity  ABC   •  If  /  ElseIf  /  Else  statements   #if($condi5on_1)          Condi5on  1  was  met   #elseif($condi5on_2)          Condi5on  2  was  met   #else            Another  condi5on  was  met   #end   •  AND  /  OR     #if($condi5on_1  &&  $condi5on_2)    …    #end   #if($condi5on_1  ||  $condi5on_2)    …  #end  
  • 4. Velocity  ABC   •  Lists   #set($mylist  =  [])   $mylist.add("asd")   $mylist.add(123)   $mylist.get(0)   •  Maps   #set($contentList  =  $!{contents.getEmptyList()})     #set($item  =  $!{contents.getEmptyMap()})     #set($_dummy  =  $item.put('guid',  $!content.get('iden5fier')))     #set($_dummy  =  $item.put('5tle',  $content.get($5tleField)))   #set($_dummy  =  $!contentList.add($item))    
  • 5. Velocity  ABC   •  Lists  and  Foreach     #foreach($item  in  $myList)        $item.5tle  <br/>     #end   •  Velocity  Comments   ##  Commen5ng  one  line   #*      Commen5ng                Mul5ple  lines   *#  
  • 6. Velocity  and  dotCMS   •  Useful  variables:   –  $EDIT_MODE   –  $CONTAINER_NUM_CONTENTLETS   –  $VTLSERVLET_URI  
  • 7. Velocity  and  dotCMS   •  View  Tools  are  configured  in:   –  dotCMSWEB-­‐INFtoolbox.xml   •  Three  types  of  view  tools:   –  Velocity  view  tools:  org.apache.velocity.tools….   –  dotCMS  view  tools:   com.dotmarke5ng.viewtools….   –  Customized  view  tools:  plugins  
  • 8. Velocity  and  dotCMS   •  Velocity  View  Tool   samples:   –  MathTool   –  ListTool   –  DateTool   hpp://velocity.apache.org/tools/devel/javadoc/  
  • 9. Velocity  and  dotCMS   •  dotCMS  View  Tool   samples:   –  CategoriesWebAPI   –  WebAPI   –  ContentsWebAPI   hpp://www.dotcms.org/api/  
  • 10. Velocity  and  dotCMS   •  org.apache.velocity.tools.generic.MathTool:   –  java.lang.Number  add(java.lang.Object  num1,   java.lang.Object  num2)   –  java.lang.Number  div(java.lang.Object  num1,   java.lang.Object  num2)   –  java.lang.Double  getRandom()   –  java.lang.Number  max(java.lang.Object  num1,   java.lang.Object  num2)   –  java.lang.Number  sub(java.lang.Object  num1,   java.lang.Object  num2)    
  • 11. Velocity  and  dotCMS   •  org.apache.velocity.tools.generic.ListTool:   –  java.lang.Boolean  contains(java.lang.Object  list,   java.lang.Object  element)     –  java.lang.Object  get(java.lang.Object  list,  int  index)     –  java.lang.Boolean  isEmpty(java.lang.Object  list)     –  java.lang.Integer  size(java.lang.Object  list)    
  • 12. Velocity  and  dotCMS   •  org.apache.velocity.tools.generic.DateTool:   –  java.u5l.Date  getDate()   –  java.lang.Integer  getDay(java.lang.Object  date)   –  java.lang.Integer  getMonth(java.lang.Object  date)   –  sta5c  java.u5l.Date  getSystemDate()   –  java.lang.Integer  getYear(java.lang.Object  date)   –  java.u5l.Date  toDate(java.lang.Object  obj)   –  java.lang.String  toString()  
  • 13. Velocity  and  dotCMS   •  CategoriesWebAPI:   –  List<Category>  getChildrenCategoriesByKey(String   key)   –  Category  getCategoryByKey(String  key)   –  Category  getCategoryByName(String  name)   –  List<Category>  getChildrenCategories(Category  cat)   –  List<Category>  getChildrenCategories(Inode  inode)   –  List<Category>  getChildrenCategories(String  inode)   –  String  getCategoryKeyByContentlet(String   contentletInode)  
  • 14. Velocity  and  dotCMS   •  WebAPI:   –  int  parseInt(String  num)   –  int  parseInt(int  num)   –  String  toString(long  num)   –  boolean  isSet(String  input)   –  List<String>  splitString(String  str,  String  sep)   –  String  encodeURL(String  url)   –  List<Contentlet>  getContentletsByCategory(String   catInode)   –   String  getContentIden5fier(String  parsePath)   –  String  getUserFullName()  
  • 15. Velocity  and  dotCMS   •  ContentsWebAPI:   –  Contentlet  getContentByInode(String  inode)   –  Structure  getStructureByType(String  structureType)   –  Structure  getStructureByInode(String  structureInode)   –  Field  getFieldByName(Structure  st,  String  fieldName)   –  List<Contentlet>  getContents(String  structureType,   String  categoryName)   –  List<Category>  getContentletCategories(String  inode)     –  List  getEmptyList()  
  • 16. Examples   •  Dynamic  Banner   •  Category  Example   •  News  Pull   •  Simple  Year  Archive