Closed lf-jeremy closed 7 years ago
Actually, include tags are not parsed. Bundle just scans configured directories for *.twig files, parses them and processes webpack_asset
function calls.
So, probably your included twig file is in some different directory, which is not scanned for twig templates. Could that be the case?
Do you have enabled_bundles
or twig.additional_directories
configured in config.yml?
The partial template I experienced this with was directly in my AppBundle's Resources/views/ directory and not in a subdirectory or another directory.
I do not have enabled_bundles
or twig.additional_directories
configured, but I can verify in my var/cache/dev/appDevDebugProjectContainer.xml file that my actual collection of enabled_bundles includes my AppBundle. Other twig files (including sibling twig files in the filepath) in my AppBundle have assets added to the manifest when webpack_asset
is called.
I figured out my issue - the bundle was globbing for twig templates expecting the .twig extension, but some of my partials omitted the extension (e.g. partial.html instead of partial.html.twig). I tried checking that before, but I must have not cleared the app cache fully before troubleshooting other possibilities.
Once I changed my partial to {name}.html.twig, it worked perfectly. Thanks!
If a twig template includes another template, and the included template calls
webpack_asset
with an image reference, that file is not included in the manifest and will throw an exception during rendering:E.g.,
Testing the same call to
webpack_asset
directly in a primary template and not an included partial, it works (showing this is not a case of an erroneous path). Incidentally, if you previously include the same image and it is already in the manifest, loading the image in an included twig template works fine, but that is not practical.I have not tested loading other asset types besides images, but I'd imagine using images inside an included partial twig template is a common use case for the sake of re-use, organization, and keeping templates slim.