question about the readme examples' logic
olets opened this issue · comments
Henry Bley-Vroman commented
The README provides examples like
{% do getCookie('marvin') %}
{# Get the cookie using 'getCookie' function #}
{% do craft.cookies.get('marvin') %}
{# Get the cookie using 'get' variable #}
{% if getCookie('marvin') %}
{% set myCookie = getCookie('marvin') %}
{{ myCookie }}
{% endif %}
Since (in my tests — I haven't dug into the plugin source) getCookie()
and craft.cookies.get()
return null
if the requested cookie doesn't exist, it seems like that could be simplified to
{# these two do the same thing #}
{% set myCookie = getCookie('marvin') %}
{{ myCookie }}
{% set myCookie = craft.cookies.get('marvin') %}
{{ myCookie }}
I'd be happy to submit a readme PR, but wanted to first understand whether I'm missing some plugin-specific need to shield the set
with the if
and do
?
Andrew Welch commented
You're right, I was just showing how you might do conditional logic based on whether the cookie is set or not though.
You do not need to shield any of the routines with the conditionals.