SlideShare una empresa de Scribd logo
1 de 16
Descargar para leer sin conexión
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	
  

Más contenido relacionado

Similar a 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 a 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
 

Más de 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
 

Más de 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
 

Último

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 

Último (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

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