I am working with Jekyll and I have the string balh blah blah&garbage **&*&% garbage <h1>TITLE</h1> &^*$%"
Is there a way to grab TITLE? I have looked at the functions here but I don't see something that I can use.
split
to the rescue !
{% assign str = 'garbage <h1>TITLE</h1> moregarbage' %}
{% assign a = str | split: '<h1>' %}
We now have garbage
in a[0] and TITLE</h1> moregarbage
in a[1]
{% assign b = a[1] | split: '</h1>' %}
We now have TITLE
in b[0] and moregarbage
in b[1]
I know this is ancient, but for anyone else coming across it: https://shopify.github.io/liquid/basics/operators/
contains contains checks for the presence of a substring inside a string.
{% if product.title contains "Pack" %} This product's title contains the word Pack. {% endif %}
contains can also check for the presence of a string in an array of strings.
{% if product.tags contains "Hello" %} This product has been tagged with "Hello". {% endif %}
contains can only search strings. You cannot use it to check for an object in an array of objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With