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

kordix's avatar

Saving "{{" in a database and showing it in the view

I want to make an app to store code snippets in the database and pass them to the view. Everything works fine, but if it contains double curly braces "{{ }}" it gets knotched up, the site blinks for a moment and then it shows nothing.

I tried {!! !!} , htmlentities(), html_entity_decode, and some Blade directive it does not work

Yet so simple but so annoying im searching for solution long time maybe you can help

0 likes
6 replies
rin4ik's avatar

did you try like below? (ctrl+f5) after in browser

{!! html_entity_decode($variable) !!}
Cronix's avatar

Can you give an example of what this data containing the curly braces actually looks like?

It could be that since your data containing the braces coming from the db aren't actually a part of the hardcoded file.blade.php template, they won't get parsed as blade directives.

kordix's avatar

Yes I tried exactly like that {!! html_entity_decode($variable) !!}

Just anything between curly braces f.e. {{ product.name }} wouldn't work, { product.name }} will.

Cronix's avatar

If they aren't a part of the actual file.blade.php template, they won't get parsed.

1 like
Snapey's avatar

I assume these are part of a Vue template?

If you want these passed to the view as-is you can escape with @

search and replace {{ with @{{ ?

1 like
click's avatar

You are using VueJS I assume or at least did not disable it? The problem is that VueJS is seeing a {{ and thinks he needs to parse a variable. This is a known issue and can turn into a vulnerability that opens up your website to XSS. This is discussed in multiple tickets on this forum. One of them is https://laracasts.com/discuss/channels/laravel/overriding-e-or-any-of-the-laravel-helpers?page=1

There are multiple solutions:

  1. Disable vuejs at all if you don't use it.
  2. Add v-pre to each html element where you do not want to parse vuejs brackets. https://vuejs.org/v2/api/#v-pre
  3. Make sure you never have {{ or }} in your variables. In the topic above devonblzx solves it by extending the laravel escape method to make sure {{ and }} are replaced by { { and } }
  4. Another solution is to disable delimiters following this comment: https://github.com/vuejs/vue/issues/4223#issuecomment-294864675
1 like

Please or to participate in this conversation.