Highlighter Pattern Matching

Modified on Mon, 07 Mar 2022 at 03:16 PM

When deploying your template you have a few options when choosing how to match a page. The simplest is just a list of URLs. You can just paste in a list of URLs like below and the highlighter will deploy to only those pages. When you are pasting these URLs make sure you are using the canonical URL so if the page redirects it will deploy to the final destination. For example, you may have a url https://example.org/123 that redirects to https://example.org/123-home you should use the latter as you the URL to deploy to.

The second option is use an xpath. Using an xpath is more advanced and require you to create or copy an xpath from the browser so the page only matches when a condition is true. As an example you may want to match only when a button is present. If this is the case you can actually get your browser to generate an xpath by right clicking on the element and choosing inspect. Once the inspector pops open it will have that item selected you can then right click that item and copy the xpath as in the screen shots below. 

Here we are selecting the link we want to ensure is present and clicking inspect so we can then ask the browser to generate an xpath for that item. 

You can copy the xpath and paste that in the highlighter so it will deploy only to pages that have the element present. You will have to do some manual checking to make sure unrelated pages can't be matched if this button is present on them and in the same location. 

The third option for deployment is to use URL patterns. This will match against the URL of the page using wildcards to allow different values for part of the path. 

As an example if my site my product pages on my site had the pattern of https://example.org/products/product-1 https://example.org/products/product-2 https://example.org/products/product-3 ... Then I'm interesting in varying the last part so my pattern would be /products/* which will match anything after products but won't include sub pages i.e. if I had https://example.org/products/product-1/more-details

Building off the example from above if my pattern always had products with a variable name and then more-details I have two options I can one use a single * i.e. /products/*/more-details or you might have multiple variations of more-details as well and want to match anything two levels deep so the pattern becomes /products/*/*/. This would match https://example.org/products/product-1/additional-details/ but not https://example.org/products/product-1/more-details/even-more-details. Lastly, if anything after products is the same template no matter how many sub paths it has you can use the ** so /products/** which match any URL that starts with /products regardless of how deep it goes. Since the ** ignores the rest of the URL you can't later say /**/more-details because the highlighter was first told to ignore everything so this causes undefined behaviour. Similarly is you use more than two *'s it is undefined behaviour.


The general recommendation is to only use ** when you know that all sub paths will match the same type of page and you want those pages marked up. Think of it as a shortcut for these cases. Otherwise you can use multiple *'s in various path locations to match complex structures. 

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article