fvsch / kirby-twig

Twig templating support for Kirby CMS 2. For Kirby 3, use https://github.com/amteich/kirby-twig
MIT License
70 stars 8 forks source link

cookie::get() won't work #38

Closed mhuegel closed 5 years ago

mhuegel commented 5 years ago

Hi there!

Is it possible to geht kirbys cookie::get to work with twig? Or is there any workarround?

fvsch commented 5 years ago

Hi. By default -- and on purpose -- Twig does not expose every variable, function and class that the PHP context has access to. You can manually expose some functions or static class methods as documented here: https://github.com/fvsch/kirby-twig/blob/main/doc/functions.md#exposing-static-methods

But my advice would be to create Controllers to handle this kind of logic, instead of doing it in templates. See Kirby's docs: https://getkirby.com/docs/developer-guide/advanced/controllers

mhuegel commented 5 years ago

Thanks for your fast reply!

Using a controller as suggested worked just fine for me.