Laravel blade "{{ command }}" not working correctly - php

I have this weird problem with my Laravel 5.5 version... I created the auth views using
php artisan make:auth
This command created the views controllers and everything I need to lets get stared to work. But I'm having this visualization problem
As you can see on the register view I have this problem.
The real thing is that "{{ any_command }}" is printing the code that its supose to generate instead of interprating like part of the code. But if I use {!! any_command !!} instead it seems to work propertly. What can happend to my laravel is screwed up. It has nothing to be with the artisan auth method, because I tried to create a new form (using laravel collective form helper) and get the same result.

{{ }} will escape all data before printing. So, if you write any HTML tag inside, it will be escaped and printed as is. Just like your example.
{!! !!} will print unescaped data. This will print the tags correctly, but you have to take care where you use it, because someone could inject unwanted data there.
So, in your case, you should use {!! !!}.
Please, refer to this question: What is the difference between {{ }} and {!! !!} in laravel blade files?

Related

Symfony 5.4 Twig misinterpreted and displays {{

for some views, I have twig that bugs,
some variables are displayed with two braces before
like this one in my code {{ version }}
displays on the interface {{ 1.0
I'm using symfony 5.4 which runs on PHP7.4
does anyone have an idea of how to fix it?
Thanks
this happens only for a few variables
I just want to display a text in a variable like this {{ myvar }}
know that myvar is 'foo'
In the browser it in the browser it returns me {{foo

How to pass a subview to a master view in Laravel?

I have a master view and depending on the URL and controller, it will load in another subview to a variable called $content, that's the idea.
Currently I am trying with:
return view("master")->with(["content" => view("pages.group")]);
So for example, if the URL is https://example.com/group/1 I am trying to get the subview included on my master template. Currently, it just gets escaped for XSS but I feel like this isn't the right way to do this?
I assume you are trying to display the sub-view content in the follwing way:
{{ $content }}
Change your syntax from {{ }} (Escaped output) to {!! !!} (Non escaped output).
{!! $content !!}
In the end after #lagbox mentioned it, using Laravel sections enabled me to use a master view and extend it when needed. https://laravel.com/docs/6.x/blade#extending-a-layout

How to echo / embed laravel view output in layout as variable

I want to use view helper like {{ render_part("user_profile"); }} in laravel layout, and render_profile will return and html,
Right now it prints as plain string and not rendering as HTML, Also I need some good guide to understand laravel blade/view compilation architecture so that i can write custom classes overriding core methods.
I've upvoted Gerard Reches answer. But if you want to render views from your controller and display the HTML in your views:
By default, Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:
{!! $myHTML !!}
Hope this helps.

VueJS variable inside URL::action in Laravel

I am new to VueJS.
I have a link using Laravel Helpers:
{{ $tournament->id }}
As it will be inside a VueJS v-for, now I need to refer to Vue variables that I load with AJAX.
So, I tried to write it like that:
#{{ tournament.id }}
But I get
Parse error: syntax error, unexpected '{' (View: /home/vagrant/Code/resources/views/tournaments/index.blade.php)
Any Idea how to mix Laravel Helper and VueJS?
First of all it looks like you're missing quotes around #{{ tournament.id }}.
But after playing around with it myself it doesn't seem possible at the moment due to routes using the same brackets as placeholders.
A workaround would be to create a simple function somewhere that generates the url with a unique placeholder and afterwards you do a str_replace call on the generated url.
That's the thing I dislike in the helpers and I have completely stopped using them. IMHO the best way to go is to create a route for that (or a Route::controller) and map those urls to a controller. and then use something like:
#{{ tournament.id }}
Your routes could be something like:
Route::controller('tournament','TournamentController');
and your function inside the controller:
function getEdit($tournament_id){
// something something
}
And something like this would work

Laravel 5: Class 'HTML' not found

I'm just getting started with Laravel. I'm in a controller method and I say:
return \View::make('scrape', $data);
Then in scrape.blade.php I have:
#extends('layouts.master');
Finally, in layouts/master.blade.php I have:
{{ HTML::style('css/bootstrap.min.css') }}
And that where things seem to fall apart and I get:
FatalErrorException in 002eb18bb71fd3ec1de058967b799d49 line 6:
Class 'HTML' not found
What am I doing wrong? Thanks for your help.
Searching on google I found this
"By default in Laravel 5.0, Html and Form are not embedded anymore."
You need to add this package to you application.
Please use above links and last change HTML to Html.
eg:
{{ HTML::style('css/bootstrap.min.css') }}
to
{{ Html::style('css/bootstrap.min.css') }}.
its working.

Categories