Mar*_*der 11 svg inline templating twig
是否可以将svg文件中的代码直接包含在twig模板文件中?
就像是:
{% include 'my.svg' %}
Run Code Online (Sandbox Code Playgroud)
这将导致:
<svg viewbox=".... />
Run Code Online (Sandbox Code Playgroud)
leS*_*oth 10
一种方法:
{{ source('my.svg') }}
Run Code Online (Sandbox Code Playgroud)
在这里阅读更多内容:https: //www.theodo.fr/blog/2017/01/integrating-and-interacting-with-svg-image-files-using-twig/
如果是主题,最好使用{{ directory }}保存主题路径的变量。
{{ source(directory ~ '/images/my.svg') }}
Run Code Online (Sandbox Code Playgroud)
小智 0
您可以通过设置新变量在 Drupal8 主题中执行以下操作:
function theme_preprocess_page(&$variables) {
$svg = file_get_contents(drupal_get_path('theme', 'socialbase') . '/images/icons.svg');
$variables['svg_sprite'] = t('svg', array('svg' => $svg));
}
Run Code Online (Sandbox Code Playgroud)
在你的树枝文件中,你可以使用以下命令打印它:
{{ svg_sprite }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11089 次 |
| 最近记录: |