在 html.html.twig 中内联 css |德鲁巴 8
Inline css in html.html.twig | Drupal 8
我想在文件 html.html.twig 中插入带有内联 CSS 的样式标签
我是 运行 以 Bartik 为主题的 Drupal 8。
我希望它在前端看起来像这样。
<style media="all">
html{background:#fff;color:#000;}body{margin:0;}...
</style>
我试过这个解决方案。
<style media="all">
{% include directory ~ '/sites/default/files/css/inline.css' ignore missing %}
</style>
但后来我只得到回复<style media="all"></style>
我尝试将自定义 CSS 添加为库,它工作正常,但我想要 <css-placeholder token="{{ placeholder_token }}">
之外的 CSS(如果我想移动它)。
不,不要那样做。
正确的方法是创建一个sub-theme (with Bartik as base) and add your styles from there: https://www.drupal.org/docs/8/theming-drupal-8/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-theme
或者,您也可以在自定义模块中执行此操作:https://www.drupal.org/docs/8/creating-custom-modules/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-module
如果你仍然坚持添加内联CSS,那就像下面这样:
<style>{{ source('sites/default/files/css/inline.css') }}</style>
我想在文件 html.html.twig 中插入带有内联 CSS 的样式标签 我是 运行 以 Bartik 为主题的 Drupal 8。 我希望它在前端看起来像这样。
<style media="all">
html{background:#fff;color:#000;}body{margin:0;}...
</style>
我试过这个解决方案。
<style media="all">
{% include directory ~ '/sites/default/files/css/inline.css' ignore missing %}
</style>
但后来我只得到回复<style media="all"></style>
我尝试将自定义 CSS 添加为库,它工作正常,但我想要 <css-placeholder token="{{ placeholder_token }}">
之外的 CSS(如果我想移动它)。
不,不要那样做。
正确的方法是创建一个sub-theme (with Bartik as base) and add your styles from there: https://www.drupal.org/docs/8/theming-drupal-8/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-theme
或者,您也可以在自定义模块中执行此操作:https://www.drupal.org/docs/8/creating-custom-modules/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-module
如果你仍然坚持添加内联CSS,那就像下面这样:
<style>{{ source('sites/default/files/css/inline.css') }}</style>