We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

hi, How to use cookie in volt??

hi, How to use cookie in volt??

I use {{ cookie.username }} in volt template, but nothing output.

Thanks.



11.0k

i'm not sure how to use cookie in volt but you can use it with DI

Register cookie in DI can only use in PHP codeļ¼Œ can't use in volt template.



93.7k
Accepted
answer
edited Nov '16

In volt you have to do:

{{ cookies.get('username').getValue() }}

// UPDATE: this also works
{{ cookies.get('username') }}

Check the example in the docs.

edited Nov '16

By default, Volt engine has access to IoC (i.e. services.php), which means that one can access any service object by it's name. So if you have a cookie service defined (or not defined, if you use Factory Default) you have access to it.