Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Twig functions #10

Merged
merged 3 commits into from
Jan 8, 2024

Conversation

psebborn
Copy link
Contributor

@psebborn psebborn commented Jan 5, 2024

This fixes #9 , adding support for custom functions.
Usage gudelines:

Add a functions object to the Twig constructor, and pass the custom functions you need into there. Use as normal within Twig templates!

import bemTwigExtension from "bem-twig-extension";
plugins: [
    // Other vite plugins.
    twig({
      namespaces: {
        templates: join(__dirname, "components/templates"),
      },
      functions: {
        bem: bemTwigExtension,
      },
      activeTheme: "zoocha",
     
    })

(NB. I also added the ability for passing in the 'active theme' as sometimes I've used that in projects, and it can be helpful)

@larowlan
Copy link
Owner

larowlan commented Jan 5, 2024

This looks good to me

There's some test twig files and it would be good to add one for this functionality

@larowlan
Copy link
Owner

larowlan commented Jan 7, 2024

I wonder if we should change it from 'activeTheme' to a more generic 'globalContexts' that allows passing other values too?

@larowlan larowlan merged commit 2b29d27 into larowlan:main Jan 8, 2024
3 checks passed
@larowlan
Copy link
Owner

larowlan commented Jan 8, 2024

The final code uses globalContext: {} instead of special casing active_theme - example here

@larowlan
Copy link
Owner

larowlan commented Jan 8, 2024

@psebborn
Copy link
Contributor Author

psebborn commented Jan 9, 2024

Nice one, thank you for adding the tests, I hadn't got round to looking at them yet. I wasn't aware of globalContext - nice learning for me :)

@larowlan
Copy link
Owner

larowlan commented Jan 9, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Twig functions
2 participants