zahra_oveyedzade
zahra_oveyedzade

Reputation: 1200

Dynamic data-attribute in Blade

There is a subview named "x.blade.php" like this:

<div class="card">
<div class="card-body">
    <input type="radio" id="star5" name="rating" class="star" data-index = "5"  data-type="" /><label for="star5" title="5 star"></label>
</div>

and then this subview is included in the main view by this code:

@include('x', ['type' => "file"])

The main goal is that I want to make "data-type" attribute in input tag in subview, dynamic and specify it by this part in @include

['type' => "file"]

I want it to be "file" type or "article" type. e.g. => data-type="file" or data-type="article" but this code does not work properly.

Is there a way to set data-* attribute in @include of blade template?

Any hint is appreciated,

Upvotes: 1

Views: 1911

Answers (1)

zahra_oveyedzade
zahra_oveyedzade

Reputation: 1200

The solution is just using a double curly brace for $type variable just like below:

<input type="radio" id="star1" name="rating" class="star" data-index = "1" data-type="{{$type}}"/>

Then the variable value is passed in data-type attribute.

Hope it helps someone,

Upvotes: 2

Related Questions