<p>YAY! I got it all working!</p>
<p>The docs from the <a href="https://verbb.io/craft-plugins/wishlist/docs/" rel="nofollow noreferrer">wishlist plugin</a> for craft cms  were wrong. Wishlist is able to store a list in a cookie, which was a demand in our project.
They've corrected the docs:<br />
<a href="https://verbb.io/craft-plugins/wishlist/docs/feature-tour/lists#persisting-lists" rel="nofollow noreferrer">https://verbb.io/craft-plugins/wishlist/docs/feature-tour/lists#persisting-lists</a></p>
<p>The sprig cookbook was a great starting point.<br />
<a href="https://putyourlightson.com/sprig/cookbook#wishlist" rel="nofollow noreferrer">https://putyourlightson.com/sprig/cookbook#wishlist</a></p>
<p>I've created a component to add the entry into the wishlist:</p>
<pre><code>{{ sprig('_sprig/_entry', { entryId: entry.id }, {'id': 'entry'}) }}
</code></pre>
<p>Then I've created a second component that shows the wishlist and the number of items it contains (much like a shopping cart). It listens to the #entry component and updates itself:</p>
<pre><code>{{ sprig('_sprig/_wishlist', {}, {'s-listen': '#entry'} ) }}
</code></pre>
<p>The rest was easy. Showing the list and iterate over it.</p>
<pre><code>{% if list and list.items|length &gt; 0 %}
    &lt;div class=&quot;grid&quot;&gt;
        {% for item in list.items.all() %}
            {% set entry = item.element %}{# just for convienience #}
            &lt;div class=&quot;col-1-4&quot; id=&quot;{{ entry.slug }}&quot;&gt;
                &lt;a href=&quot;{{ entry.url }}?type=wishlist&quot;&gt;
                    [...]
                    &lt;h2&gt;{{ entry.title }}&lt;/h2&gt;
                    [...]
                &lt;/a&gt;
            &lt;/div&gt;
        {% endfor %}
    &lt;/div&gt;
{% else %}
    &lt;p&gt;Your wishlist is empty&lt;/p&gt;
{% endif %}
</code></pre>
<p>I hope this will help somebody.</p>

CC BY-SA 4.0
2023-11-21T13:46:26.467Z
What I forgot to say. In order to save the wishlist as cookie you need a config file and set 'cookieExpiry' => P10Y, // 0 if Session-based
outline4
CC BY-SA 4.0
2023-11-09T18:26:11.847Z
2023-11-09T18:26:11.847Z
outline4
<p>I'm a bit lost.<br />
I'd like to create a wishlist for products and save them into a cookie.</p>
<p>I don't want anybody to have a login and I don't mind if the list is not sharable and only available on the same device.</p>
<p>In my mind, the cookie would be an array that contains the product ids. The array can be updated by either removing an id or adding one.</p>
<p>Showing the products would just be iterating over the product ids.</p>
<p>Preferably I would do this in sprig.</p>
<p>I have a hard time to get started.</p>
<p>Could anybody affirm if this is possible and might walk me through on how to achieve this?</p>
<p>Any help appreciated!</p>
<p>Cheers<br />
Stefan</p>

<plugin-sprig>
I'd like to create a Wishlist and save it into a cookie, instead of having to login
# I'd like to create a Wishlist and save it into a cookie, instead of having to login

(Asked by: username_0 on 2023-11-08)

I'm a bit lost.  
I'd like to create a wishlist for products and save them into a cookie.

I don't want anybody to have a login and I don't mind if the list is not sharable and only available on the same device.

In my mind, the cookie would be an array that contains the product ids. The array can be updated by either removing an id or adding one.

Showing the products would just be iterating over the product ids.

Preferably I would do this in sprig.

I have a hard time to get started.

Could anybody affirm if this is possible and might walk me through on how to achieve this?

Any help appreciated!

Cheers  
Stefan

**Tags:** plugin-sprig


---

## 1 answers

### Answer by username_0 on 2023-11-09. Score: 2

YAY! I got it all working!
The docs from the wishlist plugin for craft cms  were wrong. Wishlist is able to store a list in a cookie, which was a demand in our project.
They've corrected the docs:
https://verbb.io/craft-plugins/wishlist/docs/feature-tour/lists#persisting-lists
The sprig cookbook was a great starting point.
https://putyourlightson.com/sprig/cookbook#wishlist
I've created a component to add the entry into the wishlist:
{{ sprig('_sprig/_entry', { entryId: entry.id }, {'id': 'entry'}) }}

Then I've created a second component that shows the wishlist and the number of items it contains (much like a shopping cart). It listens to the #entry component and updates itself:
{{ sprig('_sprig/_wishlist', {}, {'s-listen': '#entry'} ) }}

The rest was easy. Showing the list and iterate over it.
{% if list and list.items|length > 0 %}
    
        {% for item in list.items.all() %}
            {% set entry = item.element %}{# just for convienience #}
            
                
                    [...]
                    {{ entry.title }}
                    [...]
                
            
        {% endfor %}
    
{% else %}
    Your wishlist is empty
{% endif %}

I hope this will help somebody.

> **Comments:**
> **username_0**: What I forgot to say. In order to save the wishlist as cookie you need a config file and set 'cookieExpiry' => P10Y, // 0 if Session-based  

---

