techwilk / twig-hashtagify
将标签转换为HTML链接的TWIG过滤器。
v3.0.1
2024-09-10 19:27 UTC
Requires
- php: >=7.4
- twig/twig: ^3.4.3
Requires (Dev)
- phpunit/phpunit: ^9.5
- slim/slim: ^4.11
This package is auto-updated.
Last update: 2024-09-10 19:29:16 UTC
README
将标签转换为HTML链接的TWIG过滤器。提供与Slim框架路由器或基本URL一起工作的接口。
安装
- 通过composer安装。
composer require techwilk/twig-hashtagify
- 然后使用提供的接口之一配置基本URL,或者编写自己的
基本URL接口
use TechWilk\TwigHashtagify\HashtagifyUrlGenerator\BaseUrlHashtagifyUrlGenerator; use TechWilk\TwigHashtagify\HashtagifyExtension; use TechWilk\TwigHashtagify\HashtagifyRuntimeLoader; $urlGenerator = new BaseUrlHashtagifyUrlGenerator('https://example.com/hashtag/'); $twig->addExtension(new HashtagifyExtension()); $twig->addRuntimeLoader(new HashtagifyRuntimeLoader($urlGenerator));
Slim路由器接口
将以下扩展作为TWIG依赖项添加
use TechWilk\TwigHashtagify\HashtagifyExtension; $twig->addExtension(new HashtagifyExtension());
在您的TwigMiddleware
之后添加以下中间件来设置我们的依赖项
use TechWilk\TwigHashtagify\HashtagifyMiddleware; $app->add(HashtagifyMiddleware::createFromContainer($app, 'route-name', 'argument-name'));
使用
作为标准TWIG过滤器使用
{{ 'this text with #hashtags' | hashtagify }}
示例
将这个转换为
This is some text with #hashtags in it
变成这个
This is some text with <a href="http://example.com/hashtag/hashtags">#hashtags</a> in it