nystudio107 / craft-cookies

A simple plugin for setting and getting cookies from within Craft CMS templates.

Home Page:https://nystudio107.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

question about the readme examples' logic

olets opened this issue · comments

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?

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.