Laravel 4: How to embed raw HTML?

Is there any simple way how to label raw HTML? I have it:

{{ Form::label('firstName', 'First name <em>*</em>', array('class' => 'input_tag')) }} 

and he produces:

 <label class="input_tag" for="firstName">First Name &lt;em&gt;*&lt;/em&gt;</label> 

BUT the EM tag is not interpreted as it should be. I want:

 <label class="input_tag" for="firstName">First Name <em>*</em></label> 
+7
source share
7 answers

Using sprintf in macro much faster than redecoding:

 Form::macro('rawLabel', function($name, $value = null, $options = array()) { $label = Form::label($name, '%s', $options); return sprintf($label, $value); }); 
+10
source

use HTML :: decode ():

http://forums.laravel.io/viewtopic.php?id=1772

 {{ HTML::decode(Form::label('firstName', 'First name <em>*</em>', array('class' => 'input_tag'))) }} 
+11
source

You can create a helper function (macro) like:

 HTML::macro('raw', function($htmlbuilder) { return htmlspecialchars_decode($htmlbuilder); }); 

In your opinion:

 {{ HTML::raw(Form::label('input_firstname', 'PrΓ©nom <sup>*</sup>')) }} 
+1
source

I often use raw html to enter forms and labels, as it is easier for me to read and use html5 attributes such as required and placeholder. This form is a good example of using raw html with Input :: old, which allows you to capture old input. https://github.com/Zizaco/confide/blob/master/src/views/login.blade.php

0
source

For the required inputs, instead of adding HTML to the label, I add the "required-input" class (or something else).

Then I have the following CSS rule

 label.required-input:before { content: ' * '; color: #f00; } 

This will work if you do not need to have <em β†’ </em> to read from the screen. But you can add a required flag to the input.

0
source

Got it using the helper function e (), which uses htmlentities () to format your tags, and that is converting your tag to &amp;lt;em&amp;gt;*&amp;lt;/em&amp;gt; .

A quick and (very) dirty fix is ​​to add this to your start.php or somewhere else before the first call to Helpers.php:

 function e($value) { return $value; } 

But this is far from ideal.

-one
source

I believe the label Form :: ($ name, $ value, $ attributes, $ escape_html) takes a fourth parameter, which indicates whether html should be avoided. The default value is true. Therefore, if your expected result is italics *, pass false as the fourth parameter.

-2
source

All Articles