wearejust / kirby-twig

Twig templating support for Kirby CMS
MIT License
14 stars 3 forks source link

Vite and Twig? #2

Closed dannystarkDE closed 9 months ago

dannystarkDE commented 9 months ago

Does anyone use the plugin in combination with Vite?

I use the basic installation of https://github.com/arnoson/kirby-vite-basic-kit. However, all I get from Twig is the message "Unknown "vite" function. Did you mean "site"?".

I would appreciate any help.

andrepimpao commented 9 months ago

You need to expose the vite function to be available in your templates https://github.com/wearejust/kirby-twig/blob/master/doc/functions.md#exposing-a-function.

Something like:

// config/config.php

return [
  'wearejust.twig.env.functions' => [
    'vite' => 'vite'
  ]
];

And in your template:

{{ vite().js('path/to/app.js')|raw }}

Note that I added |raw at the end because Twig escapes strings by default.

Hope it helps!

dannystarkDE commented 9 months ago

Thank you very much. That works!