JavaScript Condition

JavaScript condition is the most flexible way to assign templates. There you can use native JavaScript expressions as well as Flamingo API expressions. In the Condition field , you should specify the expression you need.

Example 1: Assign a template to multiple pages by matching content with regular expression and XPath

You can use the code below to assign a template to multiple pages by matching content with regular expression and XPath expression:

return (/[d]+/.test(Flamingo.XPath.value('//*[@id="ctl00_ContentPlaceHolder1_pnlStep12"]/@name')))

The template with such condition will be applied to page(s) where:

  • specified id and the name attribute matching the regular expression are available
  • HTML element and its attribute name is taken by XPath ‘//*[@id=”ctl00_ContentPlaceHolder1_pnlStep12”]/@name’
  • through Flamingo API function Flamingo.XPath.value().
  • the value received by XPath is compared by standard JavaScript function test of the regular expression /[d]+/ .

Example 2: Assign a template to multiple pages by matching domain

To assign a definite template to all pages available on the specified domain, you should use the code below:

return location.hostname == "blog.mysite.com"

The template will be applied to pages of the blog.mysite.com domain.