octobercms - OctoberCMS:如何从 Twig 调用 Storage::url()?
问题描述
在 Laravel 5.5 中,我使用以下函数从文件系统或云中调用资产:
<link href="{{ Storage::url('assets/my.min.css') }}" rel="stylesheet">
我知道我可以使用<img src="{{ 'banner.jpg'|media }}" />
,但这迫使我只能使用媒体管理器。在 Laravel 中,我可以通过 alter in 在本地文件系统和云之间切换'default' => env('FILESYSTEM_DRIVER', 'local'),
,config/filesystems.php
非常方便。
这就是为什么我的问题是我如何Storage::url()
在 twig 中使用 OctoberCMS?
解决方案
在树枝中都取决于主题,所以你可以使用theme
过滤器
包含您可以使用的 js 文件
<script type="text/javascript" src="{{ 'assets/js/menu.js'|theme }}"></script>
它将从当前主题中获取 url,然后assets/js/menu.js
对于 css 相同
<link href="{{ 'assets/my.min.css'|theme }}" rel="stylesheet">
更多信息:https ://octobercms.com/docs/markup/filter-theme
并包含 js 和 css 组件,您可以使用帮助程序https://octobercms.com/docs/plugin/components#component-assets
// inside component
public function onRun()
{
$this->addJs('/plugins/acme/blog/assets/javascript/blog-controls.js');
$this->addCss('assets/css/hello.css');
}
您可以添加然后使用它的插件也是如此。
如有任何疑问,请发表评论。
推荐阅读
- postgresql - 如何修改使用 sequelizeJS 生成的默认日期时间格式
- node.js - 获取错误响应,状态为:404 Not Found for URL
- spring - Oauth2、本机应用程序和令牌窃取
- elasticsearch - Elasticsearch 中的 MUST 和 MUST_NOT 查询
- java - 从字符串变量中的休息服务获取异常
- javascript - Javascript Date 对象未显示正确的月份
- c# - EF Core SQLITE - SQLite 错误 19:'UNIQUE 约束失败
- python - 将 Python 添加到 Windows 路径
- javascript - String .replace() does not work with '$' symbol
- ios - 将 alpha 设置为 0.0 后无法点击 UIButton,即使重置为 1.0