ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## 搜索页 HkCms有提供基础搜索页,在默认模板下的index目录下**search.html**文件有演示案例。 ## 使用方法 1. 调用方式 复制以下表单放置任意位置即可,定义`model_id`,以查询不同的副表模型数据。 ~~~ <form class="d-flex" action="{:url('/search/index')}" method="get"> <!-- model_id的value值为空时,无法获取副表的字段。 --> <input type="hidden" name="model_id" value=""> <input class="form-control" type="search" name="keyword" placeholder="关键字" aria-label="Search"> <button class="btn btn-primary">搜索</button> </form> ~~~ 2. 搜索结果页 结果页放到index目录下,并命名search.html - 结果页变量 ~~~ $__param__ // 查询(搜索)参数 $__modelInfo__ // 所有模型信息 $__SDATA__ // 搜索到的列表结果 $__SPAGE__ // 分页数据 ~~~ ## 变量说明 - $_\_param__ 搜索参数数组,里面包含:keyword(用户搜索的关键字)、model_id(模型ID) 、category_id(模型ID) 、orderby(排序字段)、ordermode(排序类型,asc=升序,desc=降序) ~~~ {$__param__['keyword']} // 搜索的关键字 {$__param__['category_id']} // 筛选的栏目ID {$__param__['model_id']} // 筛选的模型ID ~~~ - $_\_modelInfo__ 模型信息,使用volist输出 ~~~ {hkcms:volist name="__modelInfo__"} 模型别名:{$item.alias} {/hkcms:volist} ~~~ - $_\_SDATA__ 结果列表 ~~~ {hkcms:volist name="__SDATA__"} 标题:{$item.title}、更多字段前往后台字段管理里面查看 {hkcms:color name="$item.title"} // 搜索结果文字高亮 {/hkcms:volist} ~~~ 搜索文字高亮使用(v2.2.3.220920+)下面的标签: {hkcms:color name="$item.title"} ,默认是红色,如果想改成蓝色并加粗如下: ~~~ {hkcms:color name="$item.title" style="color:blue;font-weight:bold"} ~~~ 高亮效果图 ![](https://img.kancloud.cn/4b/a2/4ba206107e85b16a800c0138fa91aa9f_468x186.png) - $_\_SPAGE__ 分页对象,使用contentpage分页标签,了解更多前往内容列表分页标签查看 ~~~ {hkcms:contentpage name="__SPAGE__" item="home,pre,pageno,next,last,info" mobile_item="pre,pageno,next" pre="&laquo;" next="&raquo;" /} ~~~