Template Guides

PDF Template

You can also generate a PDF version of your lists, for your users to download and save, or share with other users.

To get started, ensure you've set up the PDF Template under the Configuration for Wishlist. Feel free to adjust any additional PDF-related options as required.

Then, you'll want to fetch the list you want to generate the PDF for.

{% set list = craft.wishlist.getUserList() %}

{% if list.id %}
    <a href="{{ list.getPdfUrl() }}">Download your wishlist</a>
{% endif %}

Here, we're generating a link for the user to click on to download their PDF. When clicked, their PDF will be downloaded. The URL will look something similar to:

https://craft.test/actions/wishlist/pdf?listId=123&reference=abcdefghij

The list owner can download the PDF directly. Anyone else must use a generated URL containing the list’s exact sharing reference. A numeric list ID on its own does not grant access.

Wishlist limits uncached generation to five renders per authenticated user or guest client address and 20 renders per list every 15 minutes, with no more than four renders running concurrently. Identical output is cached for five minutes using the current viewer, request, list, site, template and PDF settings as context. List and item changes invalidate cached output; changes to other data used by a custom template can remain cached for up to five minutes. Template HTML larger than 2 MiB is rejected before PDF rendering.

These protections use Craft’s configured cache and mutex components. Multi-node installations must use shared persistent implementations for both components so render limits and cached output apply across every node.

Additional Parameters

You may find the additional parameters useful, especially during testing and development of these templates. Simply use one of the following values to append to the URL produced above.

  • &attach=false - Add this to not force the PDF to download. Instead, it'll be rendered inside the browser window. This will still render as a PDF and is useful for debugging layout issues.
  • &format=plain - Produces the same template as HTML, as opposed to PDF. Again, useful for debugging layout issues, or quickly prototyping layouts.

Template

In order for the user do have something to download, you'll want to generate the actual template used by the PDF. Create a template for the path you've set in your PDF Path under the Configuration. By default, the path to the PDF template is _pdf/wishlist.

Template Variables

In the template itself, you'll have access to the following Twig variables:

VariableDescription
listThe List object.

Example Template

Below is an extremely basic example, we encourage you to get creative to make great-looking templates!

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<style>
    html {
        margin-top:0.2in !important;
        margin-left:0.2in !important;
    }

    body {
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        font-size: 13px;
        line-height:1.4em;
        font-weight:bold;
    }
</style>
</head>

<body>
{% for item in list.getItems() %}
    <div>
        <p>
            <strong>Name:</strong> {{ item.title }}<br>
            <strong>URL:</strong> {{ item.element.link }}<br>
            <strong>Created:</strong> {{ item.dateCreated | date('short') }} {{ item.dateCreated | time('short') }}
        </p>
    </div>
{% endfor %}
</body>
</html>