Laravel5 render html::linkroute - php

i am using html::linkroute however the link tag and contents are being put on the screen rather than rendered, is this a bug?
The code i am using
{{ HTML::linkRoute('admin.users.edit', $user->display_name, array($user->id)) }}
the output in the browser
Prof. Trent D'Amore

In Laravel 5 {{ ... }} escapes the output, thats why you see the HTML in the browser. Instead you should use {!! ... !!} which will render the raw output to the browser. So this will work:
{!! HTML::linkRoute('admin.users.edit', $user->display_name, array($user->id)) !!}
You can read more about Laravel 5 Blade changes.

Related

Retrieve data without html tag in Laravel

Content in my database: <h2> This is heading text</h2>
I want to retrieve this without html tags but with bold format as <h2> tag does .
In this case: strip_tags() only removes the tags.
By default once you do {{ $foo->bar }} laravel retrieves everything as plain text. You may be looking at retrieving it this way instead. {!! $foo->bar !!}
You can use this using blade template :
{!! $data->content !!}
Using above code remove all HTML tags .
If you want to retrieve HTML code to page you can use the below code :
{!! html_entity_decode($data->content) !!}
If you want to get Text Plan only without HTML code use the below code :
{{htmlspecialchars(trim(strip_tags($data->content)))}}
For more details : Displaying Data - Laravel

Laravel : when i return styled string from database its appear with the html tags

I store in the database some text with html tags using ckeditor , and when i print the text in laravel blade the text appears styled but the tags appears with the text check the process below .
This is the stored text in mysql database :
<h4>English</h4>
And this is the div section in the blade where the text printed
<div class="col-md-12">
{{$post->title_ar}}
</div>
And this is the result
<h3> English </h3>
i want the text appear without tags like this : English
It should work if you change your syntax from {{ }} to {!! !!}.
It also depends what version you are using...
V-5 Should be: {!! !!}
use {!! !!} not {{ }}, it will work with you.

Laravel 5 echo out session variable containing html in blade

I did a redirect in laravel:
return redirect('admin')->with($returnData);
$returnData is a string that contains a bootstrap info div with the result from the controller. Almost everything is working except when the page loads again it shows the html on the page as if it were text, brackets and everything. If I use this:
#if(!empty(Session::get('error'))) {{ Session::get('error')}} #endif
Then it shows is as pure text. If I change it to
<?php if(!empty(Session::get('error'))) { echo Session::get('error'); } ?>
It works fine. Im ok keeping it like this but I would rather utilize Blade / Laravel as its supposed to be used so I was wondering if there is a way to have the #if statement show the rendered html and not the text version?
I would recommend returning just the error message then in your view create the div. So if you were to change the layout of the view, you would it in one place.
#if(Session::has('error'))
<div class="alert alert-danger">
{{ Session::get('error')}}
</div>
#endif
hope this help.
To show the rendered HTML you should use {!! $variable->coontent !!} in your view, and this gonna convert your HTML text to render
May this example will help you.
Try this
#if (session('Error'))
<div class="alert alert-success">
{{ session('Error') }}
</div>
#endif
If you want to display plain text from error without any HTML entities you can simply use:
{{ Session::get('error') }}
or
{{ session('error') }}
If you have HTML entities in your variable then use:
{!! Session::get('error') !!}
Try changing your blade code to following.
#if(!empty(Session::get('error')))
{!! Session::get('error') !!}
#endif

How To Put HTML Code In Laravel Function?

I stumbled upon this problem. I am using twitter bootstrap. I generate form elements like this:
{{ Form::button('Save', array('class'=>'btn btn-success')) }}
This is alright. But when I want to put an icon before the 'Save' like this,
{{ Form::button('<i class="icon-ok"></i> Save', array('class'=>;'btn btn-success')) }}
The <i> tag is not interpreted as it should be.Is there any workaround on this? How do I do this?
Any Body Give Some Idea
Thanks in advance.
You can use the HTML::decode method to wrap your button.
Example:
{{ HTML::decode(Form::button('<i class="icon-ok"></i> Save', array('class'=>;'btn btn-success'))) }}
HTML::decode converts entities to HTML characters according to laravel's api, found here:
laravel api
What version of Laravel are you using?
In Laravel 5, Blade has changed so that {{ }} is escaped by default (therefore not rendered as HTML by the browser) and you should use {!! !!} instead.

Laravel Model Binding and HTML Editor

I'm using a HTML editor for fields, and having problem on printing the content on edit form using Model Binding and resource controller.
Since the editor accepts HTML tags, they not escaped (htmlentities way), and inserted raw.
While this might not be a problem, I need to find a way to print that text back into HTML editor with all HTML parsed, due to needed editing of the text.
This is the field that has a HTML editor attached through JS (for insert and edit):
{{ Form::textarea('text', null, array('class' => 'form-control')) }}
Out of model binding way of creating CRUD, {{ html_entity_decode($text) }} will do the job when outputting the text back to the editor.
Question:
Is there a way to add htmlentities() to model-bind-form? I need to print back the text containing html inside HTML editor that will parse it correctly.
P.S. using Laravel's helper e() doesn't seem to solve the problem.
Thanks in advance
Have you tried passing the decoded text into the form:textarea like this:
{{ Form::textarea('text', html_entity_decode($model->text), array('class' => 'form-control')) }}

Categories