Strange issue with path strings
Here are two pieces of code, first one works and second one does not (both work in PHP Twig).
{% include "@images/icon-menu.svg.twig" %}
{% set icon_name = 'icon-menu' %}
{% include '@images/' ~ icon_name ~ '.svg.twig' %}
Second one returns Template "@images/icon-menu.svg.twig" is not defined in "/correct/path/to/components/icon.twig" at line 47.
Here is how environment is set up:
const path = require('path');
const { TwingEnvironment, TwingLoaderFilesystem } = require('twing');
const componentsDir = path.resolve(__dirname, '../../correct/path/to/components');
const loader = new TwingLoaderFilesystem([]);
if (typeof loader.addPath === 'function') {
loader.addPath(path.resolve(componentsDir, '00-quarks'), 'quarks');
loader.addPath(path.resolve(componentsDir, '01-protons'), 'protons');
loader.addPath(path.resolve(componentsDir, '02-atoms'), 'atoms');
loader.addPath(path.resolve(componentsDir, '03-molecules'), 'molecules');
loader.addPath(path.resolve(componentsDir, '04-organisms'), 'organisms');
loader.addPath(path.resolve(componentsDir, '05-templates'), 'templates');
loader.addPath(path.resolve(componentsDir, '06-pages'), 'pages');
loader.addPath(path.resolve(componentsDir, '../dist/images'), 'images');
}
const twing = new TwingEnvironment(loader);
module.exports = twing;
Edited by Henrijs Šešo