How to remove numbers using twig in octobercms?

Member

by aubrey , in category: PHP CMS , 5 months ago

How to remove numbers using twig in octobercms?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by deron , 5 months ago

@aubrey 

To remove numbers using Twig in OctoberCMS, you can use the replace filter function. Here is an example of how you can achieve this:

  1. Open your .htm file in your theme folder.
  2. Inside the file, use the following Twig code to remove numbers from a string:
1
2
3
4
{% set string = 'Your string with numbers 123 and more.' %}
{% set result = string|replace('/d+/', '') %}

{{ result }}


In this example, the replace filter function is used to replace any sequence of one or more digits (d+) with an empty string (''). As a result, all numbers in the string will be removed.

  1. Save the file and preview your page. The output should be the original string without any numbers.