Using PHP variables in an HTML element class with Blade -


i'm using laravel , blade on small project , trying dynamically assign class names generated elements in loop. however, generated elements generating literally, such "<div class='form_q' .$i>".

@for($i = 0; $i < count($formdata['form2']); $i++)   <div class='form_q'.$i>     html::attributes('class')     <div class='q'.$i.'-header'>       <h1>{{ form::label($formdata['form2']['q'.($i + 1)]['question'], $formdata['form2']['q'.($i + 1)]['type'], array('class' => 'btn btn-primary'))}}</h1>     </div>   </div> @endfor 

what's proper syntax concatenating string , variable , assigning class/attribute? alternatively, proper blade syntax generating "div" element assigned class?

you need tell blade or php want print output.

ether surround $i variables {{ $i }} or <?php echo $i ?>. blade converts php example, {{ }} converted <?php echo ?>. keep in mind you're still using php when making blade templates.

@for($i = 0; $i < count($formdata['form2']); $i++)   <div class='form_q{{ $i }}'>       html::attributes('class')       <div class='q{{ $i }}-header'>         <h1>{{ form::label($formdata['form2']['q'.($i + 1)]['question'], $formdata['form2']['q'.($i + 1)]['type'], array('class' => 'btn btn-primary'))}}</h1>       </div>   </div> @endfor 

you should go on blade docs again. http://laravel.com/docs/templates


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -