Help with Shortcode in template

I’m trying to pass an ACF field contents into a tag in a shortcode (in a template) without success.

<Field acf_file=pdf field=url /> returns the URL of a PDF attachment which I want to include in a shortcode as a “Tag in attribute” using braces. The following is not working for me inside a template:


<Shortcode>[pdfjs-viewer url="{Field acf_file=pdf field=url /}" attachment_id="15" viewer_width=100% viewer_height=800px fullscreen=true download=true print=true]</Shortcode>

The following correctly displays the URL of the PDF:

<Field acf_file=pdf field=url />

Hello!
Could you try this?

<Shortcode pdfjs-viewer url="{Field acf_file=pdf field=url}" attachment_id="15" viewer_width=100% viewer_height=800px fullscreen=true download=true print=true />

Using the Shortcode tag this way instead of as a wrapper lets you pass L&L fields to the shortcode parameters :slight_smile:

Thanks for that, that half works. This is good…

<Shortcode pdfjs-viewer url="{Field acf_file=pdf field=url}" attachment_id="15" viewer_width=100% viewer_height=800px fullscreen=true download=true print=true />

But a second embedded field does not work, eg.

<Shortcode pdfjs-viewer url="{Field acf_file=pdf field=url}" attachment_id="{Field acf_file=pdf field=id}" viewer_width=100% viewer_height=800px fullscreen=true download=true print=true />

The following individual shortcodes work:

<Field acf_file=pdf field=url />
<Field acf_file=pdf field=id />
Maybe try writing url="{Field acf_file=pdf field=url}" attachment_id="{Field acf_file=pdf field=id}" viewer_width=100% viewer_height=800px fullscreen=true download=true print=true

as <Set name=params> url="{Field acf_file=pdf field=url}" attachment_id="{Field acf_file=pdf field=id}" viewer_width=100% viewer_height=800px fullscreen=true download=true print=true</Set>

Then <Shortcode pdfjs-viewer {Get name=params}>

Actually you need to close it:

{Get name=params /}

Probably the same issue in your code. Try this:

<Shortcode pdfjs-viewer url="{Field acf_file=pdf field=url /}" attachment_id="{Field acf_file=pdf field=id /}" viewer_width=100% viewer_height=800px fullscreen=true download=true print=true />

I wish I had enough experience with the ACF integration and shortcode tag to be able to provide a solution here, but I’m not spotting the issue with your syntax.

I figured I’d at least chime in to confirm that this isn’t the issue:

Actually you need to close it:
{Get name=params /}

As noted at the very bottom of this page of the docs, “Closed tags like Field don’t need the slash / to close itself inside an attribute.”

Hi Ian,

This is a mysterious issue - I wasn’t able to track down why it’s not working, but I added a feature in the Shortcode tag to inspect what attributes are being passed. Could update to the newest plugin version, and try the following?

<Shortcode debug url="{Field acf_file=pdf field=url}" attachment_id="{Field acf_file=pdf field=id}" />

That should display the PDF’s attachment ID and URL. If both are correct, it means that correct values are being passed to the pdfjs-viewer shortcode. In that case, we might need to dig into the shortcode itself to find out why it’s not working as expected.