guilty/craft-slugify

为Craft安装添加slugify Twig扩展。

安装次数: 18,206

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 2

开放问题: 1

类型:craft插件

1.0.1 2018-11-05 15:22 UTC

This package is auto-updated.

Last update: 2024-09-07 00:17:25 UTC


README

Craft Slugify 简单地为您Craft安装添加了Twig过滤器"slugify",实际生成slug使用了cocur/slugify包。

需求

此插件需要Craft CMS 3.0.0-beta.23或更高版本。

安装

要安装此插件,请按照以下说明操作。

  1. 打开您的终端并转到Craft项目目录
cd /path/to/project
  1. 然后告诉Composer加载插件
composer require guilty/craft-slugify
  1. 在控制面板中,转到设置→插件,并点击Craft Slugify的“安装”按钮。

使用Craft Slugify

{% set posts = craft.entries.section("posts").all() %}

<h1>Table of contents</h1>
<ul>
    {% for post in posts %}
        <li><a href="#{{ post.title | slugify }}"> {{ post.title }}</a></li>
    {% endfor %}
</ul>

<hr>

{% for post in posts %}
    <article id="{{ post.title | slugify }}">
        <h2>{{ post.title }}</h2>
        <div>{{ post.bodyContent }}</div>
    </article>
{% endfor %}

Guilty AS提供