I am building a blog where I can enter php, html and javascript code, even blade template code. I found that Laravel won't print double curly brackets like these {{ }} from the blade template. or the Controller if I render the template after printing.
So to test if was php causing trouble and not printing curly brackets I did this in my Controller:
echo 'test {{ test }}';
dd();
and test {{ test }} got printed. I then removed the dd(); so the code now looked like this:
echo 'test {{ test }}';
$post = Post::where('id', $id)->first();
return view('admin.posts.edit')->withPost($post);
Now only 'test test' got printed without curly bracekts. I then commented out
//return view('admin.posts.edit')->withPost($post);
and now test {{ test }} got printed again.
It's obvious that Laravel is preventing me from printing curly brackets and is removing them. I need to be able to print them from the blade template. Why isn't it working and how to solve this?
inside a function in Controller do this
echo 'test {{ test }}';
return view('someview');
only 'test test' will be printed, remove the return view and test {{ test }} gets printed
You need to escape them, with an @.
Doesn't work: echo 'test @{{ test }}'; prints test @. Reopen this issue thanks.
Yeh, of course it does? You can't do that with an "echo". This only will do that inside a blade template file that gets compiled. Never write "echo" in a controller.
ok let me explain my situation a bit more. Lets say I enter this
<meta name="csrf-token" content="{{ csrf_token() }}">
into my post and save it to database:
now inside my template I do this: {{ $post->body }} how do you expect me now to escape the {{ }} I can't do
$post->@body or @$post->body.
So Laravel prevents me from printing {{ }} that are stored in database. I think this should be reopened unless you can show me how I can print curly brackets from template that are comming from database column.
it doesn't work test: @{{ $post->body }} prints only test: and nothing after it. Please reopen this issue
Wait, so your $post->body contains {{ }}, and you're using {{ $post->body }} to print it, and it removes the curly braces? That's probably because it's in a partial. It renders the partial, and then renders the template file using the partial. So if the partial content contains {{ }} it will render those.
You should escape the curly braces before storing them into the database, with @{{ }}.
So yeah, save it in the DB as
<meta name="csrf-token" content="@{{ csrf_token() }}">
so I entered into database via phpmyadmin and manually did what you said I put @{{ like this
<pre>
<code class="language-html"><meta name="csrf-token" content="@{{ csrf_token() }}"></code></pre>
and print with {{ $post->body }} and it prints this out
<pre> <code class="language-html"><meta name="csrf-token" content="@"></code></pre>
brackets nowhere to be seen and I am not inside a partial. I am inside a template that looks like this
@extends('layouts.admin')
@section('content')
I say reopen this issue and have Talyor look at it.
Is @taylorotwell using Laravel to build http://laravel.com How does he manage on this page https://laravel.com/docs/5.3/routing to print
{{ csrf_field() }}
Can anyone answer this question?
Try removing Vue.js ...
The {{ content }} is printed in the source code.
When I remove the shipped app.js the {{ content }} is visible.
@axyr what exactly should I remove? Is it these two lines from package.json
"vue": "^1.0.26",
"vue-resource": "^0.9.3"
@nermion I just got the same problem and goodle direct me to this post. I did what axyr told that "remove the shipped app.js" so I comment out and in app.blade.php and it's work
And make sure you add bootstrap.css and bootstrap.js manually to replace those 2 files if you plan to use it in your project
Is this still an issue? I tried copying
echo 'test {{ test }}';
return view('someview');
first run it prints test {{test}}.
second run (without return view) it still prints test {{test}}.
I haven't changed anything in my Laravel project, lot of things added though.
@VisualTrauma The problem is not exactly like that:
Controller:
return view('someview', ['test_variable' => 'test {{ test }}'])
someview.blade.php:
{{ $test_variable }}
Display
test test
Laravel 5.3
To display
test {{ test }}
I have to comment out app.js
@NghiemDuongHung Oh I see. But then again I did this on my web.php
$var = 'test {{ test }}';
return view('welcome', compact(['var']) );
in welcome.blade.php, I did
{{ $var }}
and it still prints
test {{ test }}
Was there a solution to this? As I tested this in my project and on other Laravel based site and if I make a comment, post, ect. that has a input field and enter This is a test {{ ggg }}and submit. It breaks the whole page now when trying to view that comment or post with Can't find variable: ggg in the browser console.
laravel 7.9.2, same issue with app.js (with vue). curly brackets cannot be printed or it will break the entire layout. was there a solution other than removing default app.js ?
I know this is an old thread and not sure this is exactly the issue, but yesterday I discovered you can skip elements from being compiled with Vue using v-pre.
<span v-pre>{{ this will not be compiled }}</span>
Most helpful comment
You need to escape them, with an
@.