larowlan / vite-plugin-twig-drupal

Provides a vite plugin for rendering Drupal flavoured twig files with Storybook
MIT License
15 stars 4 forks source link

Macros support? #5

Closed IHIutch closed 8 months ago

IHIutch commented 8 months ago

Does this plugin support Twig macros? I'm trying to use one in pagination/templates/pagination-unbounded, but I'm getting the following error

An error occurred whilst rendering /project/home/ihiutch/workspace/stories/pagination/templates/pagination-unbounded.twig: TypeError: Cannot read properties of undefined (reading 'valueOf')

Codesandbox

**Also, excuse the other files, I found this plugin and am in the midst of migrating (If I can get macros to work!)

larowlan commented 8 months ago

Twig.js supports it so we should be able to support it. I'll add a new test case and report back

IHIutch commented 8 months ago

I tried playing around with some simpler implementations and noticed that it seemed to work intermittently. But the error that came up (in browser) was always the same fs.statSync one

larowlan commented 8 months ago

Can you give https://github.com/larowlan/vite-plugin-twig-drupal/pull/6 a try? Test in the PR seems to show it working, even with self references. Took me a while to get it going because I naffed up the macro syntax in the test twig files :upside_down_face:

larowlan commented 8 months ago

Happy to make a release with #6 if that's easier for testing, it doesn't make things any worse

IHIutch commented 8 months ago

Seems to be working, locally. Thank you!

Also working in the codesandbox

larowlan commented 8 months ago

Cutting a new tag

larowlan commented 8 months ago

https://github.com/larowlan/vite-plugin-twig-drupal/releases/tag/v1.0.2 should be on npm

IHIutch commented 8 months ago

Tyvm, this plugin has made working with Twig and Storybook so easy!