首页 安企CMS模板标签手册 分类页面标签

分类列表标签

说明:用于获取文章、产品分类列表

使用方法:{% categoryList 变量名称 with moduleId="1|2" parentId="0" %} 如将变量定义为 categories {% categoryList categories with moduleId="1" parentId="0" %}...{% endcategoryList %}


categoryList 支持的参数有:

  • 模型ID moduleId
    moduleId 可以获取指定文档模型的分类列表如 moduleId="1" 获取文章模型的分类列表。
  • 上级分类 parentId
    parentId 表示上级分类,可以获取指定上级分类下的子分类,parentId="0"的时候,获取顶级分类。放要获取顶级分类的时候,必须指定模型ID moduleId

如果想获取当前分类的下级分类,则不需要指定 parentId。如果想获取当前分类的兄弟分类,则指定 parentId="parent",仅当在文档列表的时候有效。

categories 是一个数组对象,因此需要使用 for 循环来输出


item 为for循环体内的变量,可用的字段有:

  • 分类ID Id
  • 分类标题 Title
  • 分类链接 Link
  • 分类描述 Description
  • 分类内容 Content
  • 上级分类ID ParentId
  • 分类缩略图大图 Logo
  • 分类缩略图 Thumb
  • 下级分类前缀 Spacer
  • 是否有下级分类 HasChildren
  • 是否当前链接 IsCurrent

代码示例

{% categoryList categories with moduleId="1" parentId="0" %}
<ul>
    {% for item in categories %}
    <li>
        <a href="{{ item.Link }}">{{item.Spacer|safe}}{{item.Title}}</a>
        <a href="{{ item.Link }}">
            <span>当前第{{ forloop.Counter }}个,剩余{{ forloop.Revcounter}}个</span>
            <span>分类ID:{{item.Id}}</span>
            <span>分类名称:{{item.Title}}</span>
            <span>分类链接:{{item.Link}}</span>
            <span>分类描述:{{item.Description}}</span>
            <span>分类内容:{{item.Content|safe}}</span>
            <span>上级分类ID:{{item.ParentId}}</span>
            <span>下级分类前缀:{{item.Spacer|safe}}</span>
            <span>是否有下级分类:{{item.HasChildren}}</span>
        </a>
        <div>缩略图大图:<img style="width: 200px" src="{{item.Logo}}" alt="{{item.Title}}" /></div>
        <div>缩略图:<img style="width: 200px" src="{{item.Thumb}}" alt="{{item.Title}}" /></div>
    </li>
    {% endfor %}
</ul>
{% endcategoryList %}

多级分类嵌套调用

{% categoryList categories with moduleId="1" parentId="0" %}
{#一级分类#}
<ul>
    {% for item in categories %}
    <li>
        <a href="{{ item.Link }}">{{item.Title}}</a>
        <div class="sub-categories">
            {% categoryList subCategories with moduleId="1" parentId=item.Id %}
            {#二级分类#}
            <ul>
                {% for inner1 in subCategories %}
                <li>
                    <a href="{{ inner1.Link }}">{{inner1.Title}}</a>
                    <div class="sub-categories">
                        {% categoryList subCategories2 with moduleId="1" parentId=inner1.Id %}
                        {#三级分类#}
                        <ul>
                            {% for inner2 in subCategories2 %}
                            <li>
                                <a href="{{ inner2.Link }}">{{inner2.Title}}</a>
                            </li>
                            {% endfor %}
                        </ul>
                        {% endcategoryList %}
                    </div>
                </li>
                {% endfor %}
            </ul>
            {% endcategoryList %}
        </div>
    </li>
    {% endfor %}
</ul>
{% endcategoryList %}