frctl / twig

Use Twig templates with Fractal.
32 stars 34 forks source link

Allow passing twig.js namespaces #25

Closed julkue closed 4 years ago

julkue commented 5 years ago

https://github.com/justjohn/twig.js/wiki#user-content-namespaces

Allows specifying e.g.

const twigAdapter = require('@frctl/twig')({
  namespaces: {
    'Components': ''
  }
});

to then use:

{% include "@Components/03-common/bottom-up/bottom-up.twig" %}

I needed this because I'm using @Components in my backend to reference to the components frontend folder.

Webslung commented 5 years ago

Hey there. I'd like to see this one get merged into master if at all possible. I'm happy to make the change if that helps?

Chapabu commented 5 years ago

I've got a couple of comments before we move any further:

julkue commented 5 years ago
Chapabu commented 5 years ago

Is there any way we can get it working with render? I appreciate it's native Twig functionality, but I'm really apprehensive to break core Fractal functionality.

Re: documentation, the option itself needs documenting. If we decide to merge anyway, then the lack of @render support needs addressing. Basically, how to you use it and what does it do.

Webslung commented 5 years ago

There's a documented option to change the handle prefix but it doesn't seem to work. I can't get it to work. If it did work then you could use namespaces and then override the handle prefix to something else like in the example: %

    // use custom handle prefix
    // this will change your includes to {% include '%button' %}
    // default is '@'
    handlePrefix: '%',
samuelgoddard commented 5 years ago

I've just had a look at this and like @Webslung says the handlePrefix option doesn't appear to actually work, have any of you guys successfully had that working at any point? I'm wondering if it's just broken on this adapter. I think if that was working it would be a decent solution for this issue, as there would still be a decent fallback for people that want to use the {% render %} tag with this adapter.

Chapabu commented 4 years ago

Is there any follow up to any of the questions here? If not, I'm tempted to close rather than merge. I'll leave it a week or two though.

mihkeleidast commented 4 years ago

I'll try to fix the handlePrefix option for render tag & then finish up this PR. It's a nice feature to support.

mihkeleidast commented 4 years ago

I've updated this PR with the latest updates from master and fixed the issues.

Added docs that reference the twig.js docs on how to use namespaces. Also added comment that it may break fractal default functionality. All in all, I'm not too concerned about that since together with #43 we will allow usage of this adapter with default twig.js behavior.

Of course, if in future we find a way to make everything work at once, new PRs are welcome :)