replacing in liquid

Solved

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?

0 Likes
r8r
Shopify Expert
1473 162 488

@Andre_Borges does

{{ product.description | replace: 'THISWORD', '<img src="https://i.pinimg.com/originals/a2/c0/42/a2c04274c2e10bc712c0dc55500fb590.gif" alt="some kind of image">' }}

work?

Mario

Mario Rader [he] ★ If you want to achieve greatness, stop asking for permission. ★ Studio Mitte
• Meine Antwort war hilfreich? Hinterlass bitte ein Like.
• Meine Antwort hat Dein Problem behoben? Bitte akzeptiere sie als Lösung.
• Ich hab dir etwas erspart? Ich freue ich mich immer über eine kleine Aufmerksamkeit
• Ja, ich biete Shopify-Services & -Entwicklung und freue mich von Dir zu hören!
• Bitte teile einen Link zu der Seite, deren Problem Du in deinem Beitrag beschreibst!

• Yes, I provide Shopify-services & -development. Feel free to get in touch!
• Please share a link to the site, which you refer to in your problem description. This incredibly increases the chances of you receiving a useful answer!
• My answer was useful? Please leave a Like.
• My answer solved your issue? Please accept it as the solution.
• I saved you time or money? I'm always happy to receive a little thank you.
0 Likes
LitExtension
Shopify Partner
1228 157 217

Hi @Andre_Borges

That's very simple. You just use replace like this:

{{ product.description | replace: 'THISWORD', '<img src="https://via.placeholder.com/150" alt="image">' }}

If you can not do that, you can add me as staff and I'Il check it for you.

 

LitExtension - Shopping Cart Migration Expert
If our answer is helpful then please accept as solution!
Are you looking for a solution to migrate to Shopify? Contact us for further assistance.
Try our FREE DEMO now!
0 Likes
r8r
Shopify Expert
1473 162 488

@LitExtension which is … the same answer I gave?

Mario Rader [he] ★ If you want to achieve greatness, stop asking for permission. ★ Studio Mitte
• Meine Antwort war hilfreich? Hinterlass bitte ein Like.
• Meine Antwort hat Dein Problem behoben? Bitte akzeptiere sie als Lösung.
• Ich hab dir etwas erspart? Ich freue ich mich immer über eine kleine Aufmerksamkeit
• Ja, ich biete Shopify-Services & -Entwicklung und freue mich von Dir zu hören!
• Bitte teile einen Link zu der Seite, deren Problem Du in deinem Beitrag beschreibst!

• Yes, I provide Shopify-services & -development. Feel free to get in touch!
• Please share a link to the site, which you refer to in your problem description. This incredibly increases the chances of you receiving a useful answer!
• My answer was useful? Please leave a Like.
• My answer solved your issue? Please accept it as the solution.
• I saved you time or money? I'm always happy to receive a little thank you.

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', '<img src="{{ image }}" alt="{{ product.featured_image.alt | escape  }}">' }}
{% endif %}

     

 

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

0 Likes
r8r
Shopify Expert
1473 162 488

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

Mario Rader [he] ★ If you want to achieve greatness, stop asking for permission. ★ Studio Mitte
• Meine Antwort war hilfreich? Hinterlass bitte ein Like.
• Meine Antwort hat Dein Problem behoben? Bitte akzeptiere sie als Lösung.
• Ich hab dir etwas erspart? Ich freue ich mich immer über eine kleine Aufmerksamkeit
• Ja, ich biete Shopify-Services & -Entwicklung und freue mich von Dir zu hören!
• Bitte teile einen Link zu der Seite, deren Problem Du in deinem Beitrag beschreibst!

• Yes, I provide Shopify-services & -development. Feel free to get in touch!
• Please share a link to the site, which you refer to in your problem description. This incredibly increases the chances of you receiving a useful answer!
• My answer was useful? Please leave a Like.
• My answer solved your issue? Please accept it as the solution.
• I saved you time or money? I'm always happy to receive a little thank you.
0 Likes

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!

0 Likes
r8r
Shopify Expert
1473 162 488

@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. 

Mario Rader [he] ★ If you want to achieve greatness, stop asking for permission. ★ Studio Mitte
• Meine Antwort war hilfreich? Hinterlass bitte ein Like.
• Meine Antwort hat Dein Problem behoben? Bitte akzeptiere sie als Lösung.
• Ich hab dir etwas erspart? Ich freue ich mich immer über eine kleine Aufmerksamkeit
• Ja, ich biete Shopify-Services & -Entwicklung und freue mich von Dir zu hören!
• Bitte teile einen Link zu der Seite, deren Problem Du in deinem Beitrag beschreibst!

• Yes, I provide Shopify-services & -development. Feel free to get in touch!
• Please share a link to the site, which you refer to in your problem description. This incredibly increases the chances of you receiving a useful answer!
• My answer was useful? Please leave a Like.
• My answer solved your issue? Please accept it as the solution.
• I saved you time or money? I'm always happy to receive a little thank you.
0 Likes
Speedimize
Shopify Partner
289 46 122

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', '<img src="{{ image }}" alt="{{ product.featured_image.alt | escape  }}">' }}
{% endif %}
We Speedimize your store
Have a problem with speed performance, send me email here: hello@speedimize.io


If our advice was helpful please LIKE or ACCEPT SOLUTION
0 Likes

Hey!

@Speedimize 

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

 

0 Likes