多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# substr字符(标题)截取标签 ## 字符截取标签 可以对标题、描述等字段进行截取。 ## 格式 截取文章标题,保留10个字,超出的...显示 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>substr name<span class="token">=</span><span class="token4">"$item.title"</span> len<span class="token">=</span><span class="token4">"10"</span> dot<span class="token">=</span><span class="token4">"..."</span> <span class="token1">}</span> ``` ``` 截取描述,保留10个字,超出的...显示 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>substr name<span class="token">=</span><span class="token4">"$item.description"</span> len<span class="token">=</span><span class="token4">"10"</span> dot<span class="token">=</span><span class="token4">"...."</span> <span class="token1">}</span> ``` ``` ## 参数 参数名称可选值默认值是否必填支持版本说明name--是无限制传入待截取的变量,可以在列表循环、详情页使用len--是无限制长度、保留字数dot-...否无限制超出的标题尾部拼接字符lang--否v2.2.4.221230特定语言下有效,可用于只对中文、或英文设置不同长度的字符截取## 示例 `name` 待截取的字符变量,如下获取内容列表时,截取标题。 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>content model<span class="token">=</span><span class="token4">"6"</span> num<span class="token">=</span><span class="token4">"4"</span><span class="token1">}</span> <span class="token"><</span>div class<span class="token">=</span><span class="token4">"card-body"</span><span class="token">></span> <span class="token"><</span>h5 class<span class="token">=</span><span class="token4">"text-truncate"</span><span class="token">></span> 截取标题:保留<span class="token3">6</span>个字,后面拼接省略号<span class="token1">.</span><span class="token1">.</span><span class="token1">.</span><span class="token1">.</span> <span class="token1">{</span>hkcms<span class="token1">:</span>substr name<span class="token">=</span><span class="token4">"$item.title"</span> len<span class="token">=</span><span class="token4">"6"</span> dot<span class="token">=</span><span class="token4">"...."</span> <span class="token1">}</span> <span class="token"><</span><span class="token">/</span>h5<span class="token">></span> <span class="token"><</span><span class="token">/</span>div<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>content<span class="token1">}</span> ``` ``` `lang` 属性,用于限制指定的语言下截取的字符长度。如下,对英文截取12个字符,中文截取8个字符,多语言情况下是配合一起使用,每个语言需要写一个字符截取。 ``` <pre class="calibre20">``` <span class="token"><</span>a <span class="token">></span><span class="token1">{</span>hkcms<span class="token1">:</span>substr name<span class="token">=</span><span class="token4">"$item.title"</span> len<span class="token">=</span><span class="token4">"12"</span> dot<span class="token">=</span><span class="token4">"..."</span> lang<span class="token">=</span><span class="token4">"en"</span><span class="token1">}</span><span class="token"><</span><span class="token">/</span>a<span class="token">></span> <span class="token"><</span>a <span class="token">></span><span class="token1">{</span>hkcms<span class="token1">:</span>substr name<span class="token">=</span><span class="token4">"$item.title"</span> len<span class="token">=</span><span class="token4">"8"</span> dot<span class="token">=</span><span class="token4">"..."</span> lang<span class="token">=</span><span class="token4">"zh-cn"</span><span class="token1">}</span><span class="token"><</span><span class="token">/</span>a<span class="token">></span> ``` ```