Get substring from string in Liquid?

I work with Jekyll and I have the line balh blah blah&garbage **&*&% garbage <h1>TITLE</h1> &^*$%"

Is there a way to capture a TITLE? I looked at the functions here , but I do not see what I can use.

+10
source share
2 answers

split to the rescue!

 {% assign str = 'garbage <h1>TITLE</h1> moregarbage' %} {% assign a = str | split: '<h1>' %} 

Now we have garbage in [0] and TITLE</h1> moregarbage in [1]

 {% assign b = a[1] | split: '</h1>' %} 

Now we have a TITLE in b [0] and moregarbage in b [1]

+14
source

I know this is ancient, but for everyone who came across this: https://shopify.imtqy.com/liquid/basics/operators/

contains contains checks for the presence of a substring inside a string.

{% if product.title contains "Pack"%} This product name contains a word package. {% endif%}

Contains can also check for the presence of a string in a string array.

{% if product.tags contains "Hello"%} This product has been marked with "Hello." {% endif%}

Contains can only search strings. You cannot use it to validate an object in an array of objects.

0
source

Source: https://habr.com/ru/post/980693/


All Articles