Template Guides

Sharing Lists

A common scenario is to share a users wishlist with another user, often a guest or third-party who doesn't have an account. You can do this by using the reference attribute on a list, which makes it easy to generate unique URLs.

How your sharing implementation works is up to you – Wishlist doesn't force you into a particular scenario. As such, the below are example templates that you'll need to implement.

First, you'll want the owner of the list to be able to copy a URL to their list.

{% for list in craft.wishlist.lists().all() %}
    <h3>{{ list.title }}</h3>

    Share this list: https://example-site.com/wishlist?id={{ list.reference }}
{% endfor %}

In order to actually show the list to the public, you'll need to create a template called wishlist in your templates' directory. Note you can call this what you want, just make it match the URL above.

Then, it's just a matter of querying items based on the provided reference.

{% set reference = craft.app.request.getParam('id') %}

{% if reference %}
    {% set list = craft.wishlist.lists(false).reference(reference).one() %}

    {% if list %}
        <h3>{{ list.title }}</h3>

        <ul>
            {% for item in list.items %}
                <li>{{ item.title }}</li>
            {% endfor %}
        </ul>
    {% endif %}
{% endif %}

Remember to use craft.wishlist.lists(false) to fetch lists that don't belong to the current user, which in this case will be the new user viewing the list. Be careful with this.

The reference() parameter requires the complete reference and does not support wildcard or comparison syntax. Treat the reference as a read-only sharing key and avoid logging it or exposing it outside the intended shared URL.

Emailing

You can also email your lists directly via a form.

<form method="POST">
    <input type="hidden" name="action" value="wishlist/lists/share-by-email">
    {{ csrfInput() }}

    <input type="hidden" name="listId" value="{{ list.id }}">

    <input type="hidden" name="sender[firstName]" value="Sender">
    <input type="hidden" name="sender[lastName]" value="Person">
    <input type="hidden" name="sender[email]" value="[email protected]">

    <input type="hidden" name="recipient[firstName]" value="Recipient">
    <input type="hidden" name="recipient[lastName]" value="Person">
    <input type="hidden" name="recipient[email]" value="[email protected]">

    <input type="submit" value="Send Email">
</form>

Please note that the sender and recipient details are required, including a first name, last name and email. This is not only generally a good idea to provide for both the sender and the recipient for trust, but required to send an email. This will also help your emails look less 'spammy' if the recipient recognises the person sending the email.

If the sender is a logged-in user, you can of course set these inputs to hidden, and populate with the currentUser content from Craft.

<input type="hidden" name="sender[firstName]" value="{{ currentUser.firstName }}">
<input type="hidden" name="sender[lastName]" value="{{ currentUser.lastName }}">
<input type="hidden" name="sender[email]" value="{{ currentUser.email }}">

You can customise the content of this email via the control panel by going to Utilities → System Messages.

Email Options

You can also set the CC or BCC for the email to one or multiple emails. Multiple recipients can be provided as a comma-delimited value.

<input type="hidden" name="cc" value="[email protected]">
<input type="hidden" name="bcc" value="[email protected],[email protected]">

Each email can contain up to 10 unique recipients across the recipient, CC and BCC fields. Sending is limited to five attempts per 15 minutes for each client and each list. These limits use Craft’s configured cache and mutex, so multi-node deployments must use shared persistent implementations to enforce the limits across all nodes.

Additional Content

You can also provide any additional variables you want to access in your email templates using fields.

<input type="hidden" name="fields[personalMessage]" value="Check these out!">

And if your email templates, you could use:

{{ fields.personalMessage }}