Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

anpel's avatar
Level 1

How to escape double curly braces in a blade template?

I am trying to create a slideshow with thumbnails as shown at http://jquery.malsup.com/cycle2/demo/pager.php#adv-custom.

The markup I need to use is <img src='{{src}}' width=20 height=20>.

How can I escape the markup so that blade prints it with no errors?

I tried using {!! '{{src}}' !!} but it did not work.

0 likes
5 replies
tykus's avatar

<img src='@{{src}}' width=20 height=20>

@ escapes the curly brace for Blade compilation

5 likes
RoboRobok's avatar

Be careful with this!

This will work as expected:

@{{ foo }}
{{ $bar }}

But this won't:

@{{ }}
{{ $bar }}

$bar will be treated like normal text, rendering as:

{{ }}
{{ $bar }}

So if you want to make a random double curly braces, it will not work as expected:

Hey, I'm Johnny Moustache :@{{
{{ $bar }}

I think it's a bug.

bashy's avatar

@RoboRobok Well hopefully anpel hasn't had a bug in their code for a year+

Better late than never I guess.

RoboRobok's avatar

He probably just uses it for templating, making it always closed. But it's interesting why it works that way, why it just doesn't ignore the curly braces when it's @{{.

anpel's avatar
Level 1

I have no idea what project I needed this for or what I ended up doing. I will try to post an update when I get some more time though.

1 like

Please or to participate in this conversation.