osenco / shortcodes
Laravel 的类似 WordPress 的短代码
dev-master
2019-05-24 12:05 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-09-25 07:29:30 UTC
README
为 Laravel 提供类似 WordPress 样式的短代码
安装
通过 Composer
使用 composer 安装此包。
composer require osenco/shortcodes
用法
注册短代码
要注册短代码,请使用任何您想要使用的控制器或模型的构造方法中的辅助函数 shortcode()->add()。
将短代码标签作为第一个参数传递,并将匿名函数作为第二个参数传递,例如
\shortcode()->add('tag', function(){ return date('Y'); });
使用短代码
将短代码添加到您的内容中,可选地添加如下参数
[shortcode_tag] [shortcode_tag attr="attr1"]
渲染内容
要输出已解析短代码的内容,请使用 shortcode()->do()
将您想要输出的内容作为参数传递。
{!! shortcodes()->do($content) !!}