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

matt_panton's avatar

Escape {{ }} in vue (2.0)

I've found myself needing to output the vue template syntax literally as just curly braces on the page like {{ Some text here }} but I can't find a way to escape them so that vue doesn't try to interpret the contents. Even when I use the html codes{ and } vue still picks it up. Is there any way to get around this?

Thanks :)

0 likes
13 replies
zachleigh's avatar

What if you put it in a data property as a string and printed the property?

{{ myProperty }} 
data: {
    myProperty: '{{}}' 
} 
matt_panton's avatar

@zachleigh thanks for your reply. I think that would work but I'm getting the text from the database so it won't be possible for me :(

zachleigh's avatar

Maybe make a computed property that wraps the data in quotes?

matt_panton's avatar

@zachleigh I've figured out a workaround. I've created a component that accepts the text as a prop and then display the text in the component's template. It's not idea but get's the job done. Thanks for your help

1 like
wyatt44's avatar

@MATT_PANTON - Hey Matt,

Long shot, but any updates on how to best handle database content that may have {{'s in it?

Thanks!

wyatt44's avatar

@VMITCHELL85 - Sorry,

Should have expanded a bit, I am displaying data from the database, that may or may not have {{'s in the content. For example I have a bit of content that looks like {{ my_function }}

So I want the data to be outputted as normal, but the handlebars are breaking it. Should I be escaping these values before it is input into the database?

Thanks for the help!

bhushan's avatar

<span v-pre> {!! $thread->body !!} </span>

this works

1 like
jove's avatar

@bhushan this is almost a year old and I don't think you managed to read the issue.

bhushan's avatar

@jove i was having the same problem hour before and also tried changing curly braces with entity. actually i found exact same issue which i was facing .. i think you should read it once and the answers too !!

jove's avatar

Ok I might have misunderstood @bhushan thanks for the heads up.

1 like
cameronwilby's avatar

If you need to mix'n'match curly braces you can also try

<p v-text="`{{ some text }}`"></p>

A nice benefit is being able to interpolate values

<p v-text="`{{ ${vueDataVariable} }}`"></p>
1 like

Please or to participate in this conversation.