Skip to content
This repository was archived by the owner on Apr 20, 2022. It is now read-only.
This repository was archived by the owner on Apr 20, 2022. It is now read-only.

Twig function "source" and relative paths #30

@kostik-noir

Description

@kostik-noir

There is Twig function source which returns the content of a template without rendering it. One useful use of this function is to insert the svg file into the final HTML.
However, this only works if we specify the full path to the inserted file relative to Webpack context.

I.e. let's assume that we have such a file structure

src/
  |-- assets/
       |-- file.svg
  |-- index.twig
  |-- index.js

the content of index.twig looks like this:

<div>{{ source('....') }}</div>
  • if we use <div>{{ source('./assets/file.svg') }}</div> then the result HTML contains "Template "./assets/file.svg" is not defined." instead of content of SVG file
  • if we use <div>{{ source('assets/file.svg') }}</div> then the result HTML contains "Template "assets/file.svg" is not defined." instead of content of SVG file
  • if we use <div>{{ source('src/assets/file.svg') }}</div> then the result HTML contains content of SVG file

Files to reproduce this behavior are attached.

Any ideas how to fix this?

twig-resolve.zip

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions