Latest

Thursday, July 6, 2017

Good way to insert html atributes in blade template based on conditions in Laravel 5.3

Asked by: Diego Alves


I know that there are other question addressing this issue but they mostly cover adding a value to an attribute based on a variable. I want to include several attributes and their values based on a condition.

My first attempt, as you can see below, besides not working is not very readable:

<input
type="text" 
{{ $errors->has('bedrooms') ? "data-toggle='tooltip' data-placement='right' 
title='please, enter a value between 1 and 9.'" : "" }}

/>

Produces the html:

<input type="text"
data-toggle=&quot;tooltip&quot; data-placement=&quot;right&quot; 
title=&quot;please, enter a value between 1 and 9.&quot />


Source

No comments:

Post a Comment

Adbox