如果创建了许多“栏目模型字段”且栏目较多,且每个栏目划分的字段都不一样,那么在栏目列表页及内容详情页想要调用这些字段就比较麻烦。
分享如下自动判断当前栏目划分字段的调用方法
1、循环当前栏目划分的字段
{loop $cat['field'] $f} ... {/loop}
判断字段类型方便调用值
完整调用
show.html
{loop $cat['field'] $f} {php $fe= $ci->module['category_data_field'][$f];} {if $fe && $fe.fieldtype=="Text"} 文本字段:{$fe.name}:{$this->_options[$fe.fieldname]} {elseif $fe && $fe.fieldtype=="Radio"} 单选字段:{$fe.name}:{php $field = dr_field_options($ci->module['category_data_field'][$fe.fieldname]['id']);}{$field[$this->_options[$fe.fieldname]]} {elseif $fe && $fe.fieldtype=="Select"} 下拉选项:{$fe.name}:{php $field = dr_field_options($ci->module['category_data_field'][$fe.fieldname]['id']);}{$field[$this->_options[$fe.fieldname]]} {/if} {/loop}
循环列表中
{search ...} {loop $cat['field'] $f} {php $fe=$ci->module['category_data_field'][$f];} {if $fe && $fe.fieldtype=="Text"}文本字段:{$t[$fe.fieldname]}{elseif $fe && $fe.fieldtype=="Radio"}单选按钮:{php $field = dr_field_options($ci->module['category_data_field'][$fe.fieldname]['id']);}{$field[$t[$fe.fieldname]]}{elseif $fe && $fe.fieldtype=="Select"}{$this->_options[$fe.fieldname]} 下拉选项:{php $field = dr_field_options($ci->module['category_data_field'][$fe.fieldname]['id']);}{$field[$t[$fe.fieldname]]}{/if} {/loop} {/search}