通过 Twig 中的资产包含来自供应商库的 css 和 js 文件 [英] Include css and js files from vendor library via assets in Twig
问题描述
我想将供应商目录中某个库中的 css
和 js
文件包含到 Twig 中.
I want to include css
and js
files from a library in my vendor directory into Twig.
我通过 composer 将 morrisjs
下载到我的 symfony 供应商目录中.现在我想将主要的 css
和 js
文件包含到我的 Twig 模板中.但据我所知,asset
函数仅适用于位于 Bundle 中的文件.
I downloaded morrisjs
via composer into my vendor directory of symfony. Now I want to include the main css
und js
files into my Twig Template. But as far as I know the asset
function only works with files that are located in Bundles.
我想包含的文件位于以下路径:
The files I want to include are located in the following paths:
- project\vendor\morrisjs\morris.js\morris.js
- project\vendor\morrisjs\morris.js\morris.css
我想到了一些看起来像这样的理论代码:
I thought about some theoretical code that would look like that:
{% block stylesheets %}
<link href="{{ asset('vendor/morrisjs/morris.js/morris.css') }}" />
{% endblock %}
是否有可能直接从供应商处包含这些文件,不包含时如何包含?
Is there any possibility to include these files directly from vendor and how when not?
推荐答案
如果 morrisjs
是前端 javascript 库,则通过 npm
或 bower代码>.
If morrisjs
is a frontend javascript library then install it via npm
or bower
.
通过 composer
安装的包应该在 Resources/public
中包含所有公共资源,以便您可以使用:
Packages installed via composer
should have all their public assets in Resources/public
so you can publish them using:
$ php bin/console assets:install target [--symlink]
然后在树枝模板中使用:
Then in a twig template use just:
<link href="{{ asset('bundles/acmedemo/css/contact.css') }}" rel="stylesheet" />
这篇关于通过 Twig 中的资产包含来自供应商库的 css 和 js 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!