Been working with Craft for about a year, but today for the first time I had to modify the Redactor config to place images inside a body field. I added 'image' to my buttons array and everything seemed OK. The button appeared and I could see and select from all my sources. I selected an image and added it to my body. After I save and check the page, image appears as expected.

Next, I try the same image again, but use an image transform instead. Now when I load the page, the image is missing. When I inspect the page's source, I see this.

<img src="{asset:99:postThumbnail}">

I'm just echoing out entry.body as you'd expect. Do I need to run this through a special filter or tag to use the right.

Before saving the image, I tried viewing the markup in the RTE's HTML mode and I see this.

<figure><img src="/uploads/postThumbnail/_postThumbnail/blog-fiduciary_responsibility_thumb.jpg#asset:99:postThumbnail"></figure>

If I remove the hash from the src URL, the field is saved without issue and I can view my image. Adding it back in recreates the issue.

Is there something else I should be doing in my Redactor config, field settings, or template to make this work right?

Thanks in advance.

UPDATE: It appears that Redactor is inserting something called a reference tag into my src attribute instead of a regular path. (Why I would want this I don't know.) In the templates, I'm suppose to pass the field value through the parseRefs tag to change that reference into a proper path. Like so...

{{ entry.body|parseRefs|raw }}

But it appears that nothing is changing (tried with and without raw). I read in the comments for this old SE Q (Is it possible to use Twig in a Rich Text Field?) that parseRefs doesn't work on rich text fields, but that bring up the question of why Redactor is inserting these tags into my rich text in the first place, especially when regular old paths are working so well.

  • It appears the bit inside the curly brackets is a Reference tag and I should be able to turn it into a usable URL by running my body field through the parseRefs tag, which replaces any reference tags with the appropriate assets. When I try {{ entry.body|parseRefs|raw }} as shown in the documentation, nothing happens. So I'm wondering what else is missing. – Critical Mash Dec 8 '17 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.