1

I recently purchased the Digital Download plugin for Craft.

I'm wanting to secure a PDF download generated by another plugin called Enupal Snapshot. Reviewing the Digital Download documentation I'm not entirely sure how I would do that using the following code which generates the PDF on the fly?

Update 1

Advice has been given that we need to provide the file path. In order to get the file path in Enupal Snapshot you need to return the asset model of the PDF.

Update 2

The code was changed to reflect asset model requirment. Unfortunatly I get a "Impossible to invoke a method ("getPath") on a string variable" highlighting {% set filePath = assetModel.getPath() %} in the code.

Code

{% set pdfName = 'now'|date('Y-m-d') ~ '-' ~ date().timestamp ~ '-evaluation-' ~ companyName ~ '-' ~ firstName ~ '-' ~ lastName ~ '-' ~ submissionId ~ random(50, 500) ~ '.pdf' %}

{% set assetFolderRef = evaluationSettings.evaluationAssetRef %}
{%
    set settings = {
        filename: pdfName,
        inline: false,
        overrideFile: true,
        asModel: true,
        singleUploadLocationSource: assetFolderRef,
        cliOptions: {
            'header-html': 'evaluation-tools/evaluation/pdf-header',
            'footer-html': 'evaluation-tools/evaluation/pdf-footer',
            'orientation': 'Portrait',
            'page-size': 'A4',
            'title': 'Evaluation for ' ~ companyName,
        },
        variables: {
            passSubmissionId: submissionId,
        }
    }
%}

{% set assetModel = craft.enupalsnapshot.displayTemplate("evaluation-tools/evaluation/pdf-report", settings) %}
{% set token = craft.digitalDownload.createToken(assetModel, options) %}

<a href="{{ craft.digitalDownload.url(token) }}" class="f6 link white bg-animate bg-teal hover-bg-white hover-teal br-pill bn w-auto ph4 pv3 tc b pointer mb3">
    <i class="fas fa-file-download"></i> Download Report
</a>

1 Answer 1

2

Following the Digital download docs you may need the file path, so in order to get the file path in Enupal Snapshot you may need to return the asset model of the PDF:

{%  set settings = {
        filename: 'my-first-pdf.pdf',
        inline: false,
        asModel: true
    }
%}

{% set assetModel = craft.enupalsnapshot.displayTemplate("reports/pdf-report", settings) %}

{# Digital Download code #}
{% set token = craft.digitalDownload.createToken(assetModel, options) %}

<a href="{{ craft.digitalDownload.url(token) }}">{{ assetModel.filename}}</a>
11
  • Thanks for the support Andre - unfortunatly I get a "Impossible to invoke a method ("getPath") on a string variable" highlighting {% set filePath = assetModel.getPath() %} I have updated my full code above.
    – Dan Lee
    Commented Nov 19, 2019 at 16:22
  • Hi @DanLee, author of Digital Download here. I've (belatedly) replied to you on Github. If Enupal Snapshot is generating a real Asset, then you should be able to use Digital Download normally.
    – Lindsey D
    Commented Nov 19, 2019 at 22:28
  • Thanks @LindseyD - I think Andre has picked up the same thing. I believe I'm almost there with the soloution - I just need to get the implimentation right.Any suggestions Andre on the error I'm getting above?
    – Dan Lee
    Commented Nov 20, 2019 at 9:17
  • Hi @LindseyD - no thoughts on this?
    – Dan Lee
    Commented Nov 27, 2019 at 13:55
  • Hi @DanLee are you sure you're passing the following settings? inline: false, asModel: true
    – Andre L.
    Commented Nov 28, 2019 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.