我正在尝试使用指令中传递的参数来评估条件并返回一个像这样的字符串
Blade::directive('resource', function($page) {
return (strcmp(URL::full(), URL::to("/admin/" + $page)) == 0) ? "active" : "inactive";
});
如果传入的页面名称评估为完整URL,则返回活动字符串,否则返回非活动状态。出于造型目的
问题是$ page计算为(value)其中value是传入的字符串。我能否使用此参数对条件进行计算?
我能找到的最近的帖子是Using a Blade directive in a Blade directive,但没有答案。
谢谢
答案 0 :(得分:1)
尝试
Blade::directive('resource', function($page) {
return "<?php echo '".((strcmp(URL::full(), URL::to("/admin/" + $page)) == 0) ? "active" : "inactive")."' ?>"
});