简体   繁体   English

Blade 中的动态数据属性

[英]Dynamic data-attribute in Blade

There is a subview named "x.blade.php" like this:有一个名为“x.blade.php”的子视图,如下所示:

<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主要目标是我想在子视图的输入标记中创建“数据类型”属性,动态并通过@include中的这一部分指定它

['type' => "file"] ['类型' => "文件"]

I want it to be "file" type or "article" type.我希望它是“文件”类型或“文章”类型。 eg => data-type="file" or data-type="article" but this code does not work properly.例如 => data-type="file" 或 data-type="article" 但此代码无法正常工作。

Is there a way to set data-* attribute in @include of blade template?有没有办法在刀片模板的@include 中设置 data-* 属性?

Any hint is appreciated,任何提示表示赞赏,

The solution is just using a double curly brace for $type variable just like below:解决方案只是对 $type 变量使用双花括号,如下所示:

<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,希望它可以帮助某人,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM