How can I replace text with an image in liquid code?

Hello, been searching everywhere for an answer but i got nothing.

{{ product.description | replace: ‘THISWORD’, ‘this’ }}

Im trying to replace THISWORD with this, but i want this to be an image.

How can i do this in code?

@Andre_Borges does

{{ product.description | replace: 'THISWORD', '
![some kind of image|360x270](upload://hBHUmBY81t89IRJgkYVTLhtUmNL.gif)
' }}

work?

Mario

Hey r8r!

That doesnt work no.

To be more precise this is what im after:

{{ product_description | replace: ‘THISWORD’, ‘this’ }}

where this should be the [2] second image of the product

so it should work something like this:

{% assign image = product.images[1] | img_url: 'large' %}
{% if product.media.size > 2 %}
{{ product_description | replace: 'THISWORD', '' }}
{% endif %}

But that doesnt work!!! There is something i cant figure out

@Andre_Borges again … that’s the same code that I posted. Debugging this without having the code to work with is pretty tedious though.

That wasnt very helpful

What do you mean its your code? Its nothing like your code. It has liquid inside the img.

Does anyone has a take on this?!

Thank you!

@Andre_Borges Liquid doesn’t work like that - you’d have to capture the replace-string in a variable first. And you‘re not very friendly to people who try to help out pro bono. I’m outta this discussion.

Hi @Andre_Borges

Aibek is here from Speedimize.io

If still relevant.

You had a problem with the condition. We corrected it, because previously if the product had 2 pictures, the condition did not work. Now, if you have at least two pictures, everything will work.

Try the code as below:

{% assign image = product.images[1] | img_url: 'large' %}
{% if product.media.size > 1 %}
{{ product_description | replace: 'THISWORD', '' }}
{% endif %}

Hey!

@Anonymous

Liquid syntax error: Unexpected character ’ in “{{ product_description | replace: ‘Como Usar?’, '<img src=”{{ image }}"

This is what i got.

Im sure there is something that is not well written i just cant figure out what.

Thank you anyways for the try

Hi @Andre_Borges

The error was that you can’t reuse parentheses inside {{ }}.
Try the code below:

{% assign image = product.images[1] | img_url: 'large' %}
{% if product.media.size > 1 %}
{% capture image_html %}
  
{% endcapture %}
{{ product_description | replace: 'Como Usar?', image_html }}
{% endif %}

¯_(ツ)_/¯

@Anonymous

This is it!!!

This was what was missing, thank you!!

Its working!

Not sure why you’re getting worked up like this – in my view, you were out of line with this response:

I’m not here to teach people netiquette – you got what you needed:
good that @Anonymous translated what I wrote into code you could use.