这是一个列表页面,也是搜索页面,看的真的难受,这还只是一处条件,可以怎么优化呢?
<div class="mb10">
<a href="{{route('#',['class_type_id'=>$class_type_id,'class_region_id'=>$class_region_id,'class_theme_id'=>0,'sitecode'=>$sitecode,'deleted'=>$deleted])}}"
@if($class_theme_id == 0) class="label label-success" @endif>全部</a>
<a href="{{route('#',['class_type_id'=>$class_type_id,'class_region_id'=>$class_region_id,'class_theme_id'=>7,'sitecode'=>$sitecode,'deleted'=>$deleted])}}"
@if($class_theme_id == 7) class="label label-success" @endif>旅游</a>
<a href="{{route('#',['class_type_id'=>$class_type_id,'class_region_id'=>$class_region_id,'class_theme_id'=>4,'sitecode'=>$sitecode,'deleted'=>$deleted])}}"
@if($class_theme_id == 4) class="label label-success" @endif>旅游</a>
<a href="{{route('product.lines.index',['class_type_id'=>$class_type_id,'class_region_id'=>$class_region_id,'class_theme_id'=>5,'sitecode'=>$sitecode,'deleted'=>$deleted])}}"
@if($class_theme_id == 5) class="label label-success" @endif>旅游</a>
<a href="{{route('product.lines.index',['class_type_id'=>$class_type_id,'class_region_id'=>$class_region_id,'class_theme_id'=>8,'sitecode'=>$sitecode,'deleted'=>$deleted])}}"
@if($class_theme_id == 8) class="label label-success" @endif>旅游</a>
<a href="{{route('#',['class_type_id'=>$class_type_id,'class_region_id'=>$class_region_id,'class_theme_id'=>11,'sitecode'=>$sitecode,'deleted'=>$deleted])}}"
@if($class_theme_id == 11) class="label label-success" @endif>旅游</a>
</div>
1
2ME 2018-03-06 15:53:44 +08:00
|
2
zjsxwc 2018-03-06 16:08:58 +08:00
|
5
zjsxwc 2018-03-07 09:08:46 +08:00
@OMGZui
看了下文档,blade 也太弱了,好像不支持 macro, 那么试试 @php 里定义的函数能不能用在 blade 里 ``` @php function is_active($class_theme_id, $active_theme_id) { if ($class_theme_id == $active_theme_id) { return 'class="label label-success"'; } return ''; } @endphp <div class="mb10"> <a href="{{route('#',['class_type_id'=>$class_type_id,'class_region_id'=>$class_region_id,'class_theme_id'=>0,'sitecode'=>$sitecode,'deleted'=>$deleted])}}" {{ is_active($class_theme_id, 0) }} >全部</a> <a href="{{route('#',['class_type_id'=>$class_type_id,'class_region_id'=>$class_region_id,'class_theme_id'=>7,'sitecode'=>$sitecode,'deleted'=>$deleted])}}" {{ is_active($class_theme_id, 7) }} >旅游</a> </div> ``` |