Laravel Model Binding and HTML Editor - php

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')) }}

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.

Inserting blade code in blade code

I am trying to create a button with the Form builder
{!! Form::button('<span style="color: {!! $colour[$i] !!}" class..') !!}
The rest of the contents of the button are irrelevant, what I was trying to do was make the colour of the font $colour[$id] which worked fine when I tested it in raw HTML, but it keeps exiting the quotes when I add blade inside another blade function.
I guess I can't do that, how would I be able to use php in blade code without exiting the function? Thank you in advance.
You should pass an array with your style to this method, like:
Form::button(['style' => 'yourstyle']);

Laravel5 render html::linkroute

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.

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.

Categories