Drupal 8/9 to get a text from a URL in the Twig Template

Example 1: Set a 'pageurl' variable to contain the current page URL, and then look for a 'discount' string in the 'pageurl' variable, which means in the URL; if the string is present, the <p> tag data will be printed.

Example 2: Set the value of the 'node.field link.0.url' field to a 'linkurl' variable. and we're looking for the '/node/add' string. If this exists, the data will not be displayed; otherwise, the link 'Read More' will be displayed.



Read Next