-
Notifications
You must be signed in to change notification settings - Fork 34
Allow Twig paths to be compatible with PHP Twig #29
Comments
I figured out a workaround for my issue. Looks like Fractal does have support for paths, but twigjs does compute those paths to be relative sometimes. I found this issue twigjs/twig.js#73 that does provide a way for twigjs to not use relative paths. Anyway, gonna make a PR for this and add a config option. |
We've had this issue on Drupal 8 projects in the past. If I remember correctly, we resolved it by using an array of templates (in the docs here, right at the bottom). I think it looked something similar to: include ['@button', 'buttons/button.html.twig`] The first path doesn't resolve in Drupal, so it falls through to the second which does. I'd have to confirm this with a colleague though (@iwright?) |
Hello, As you have noticed, twig works slight different between the languages. Below are how we have worked with Drupal 8 template fallbacks and Fractal fallbacks. Please note, the Drupal 8 version is actually to make the theme child friendly too. For Drupal, we also use the components module so you can set the correct namespace. https://www.drupal.org/project/components Fractal:
Drupal 8:
I hope this helps, |
I think this one was fixed by #30. If not, then please feel free to re-open :) |
Here's my use case: I want a Fractal instance to be a component library for a Symfony project. I would like to use the same Twig templates in the Symfony codebase and in the Fractal codebase.
My problem is Fractal has a very opinionated way of including templates. You don't use a filesystem path, like PHP Twig does, instead you use a Fractal handle. If I had this directory structure:
To include the button component, I would have to do:
{% include '@button' %}
but I want to configure Fractal to include it like:
{% include 'button/button.twig %}
so that I could use the same templates with an instance of PHP Twig.
I could get around this by making a custom Twig Loader for PHP Twig, like what these guys did for Drupal 8. But I'd rather not have to introduce this complexity and requirement for using this component library. And this seems like a fairly common use case for PHP devs. Is there any way around this? Could the Twig adapter be extended to handle this use case?
The text was updated successfully, but these errors were encountered: