Bert Carremans
Bert Carremans

Reputation: 1733

Using Blade templating in HTML attribute

I want to dynamically change the attribute value for an HTML tag in a Blade template.

<span class="badge badge-blade-difficulty">

In the code above, I want to change blade to a value that can differ. I tried many things like

{{<span class=&quot;badge badge-$blogpost->difficulty&quot;>}}

or

<span class="badge badge-{{$blogpost->difficulty}}">

But these result in an error. Can anyone help? Thanks!

Upvotes: 1

Views: 2316

Answers (1)

warspite
warspite

Reputation: 632

I am not sure I totally understand your problem but as far as I can see, this could help. (please include actual errors in your questions rather than "these result in an error")

To add the attribute as a data element from your app:

<span class="badge {{{ isset($difficulty) ? $difficulty : '' }}}">

(assuming the class="badge" is what you want when difficulty is not passed. It's not clear from your question what the original value should be)

Your View::make() should pass the data to the view:

$difficulty = "badge-blade-difficulty";    
return View::make('viewname', $difficulty);

again... I am not totally sure this is exactly what you are looking for but it should get you going.

Upvotes: 1

Related Questions