1

I have created a PDF template for orders and this works fine on the front-end. However, when I click to Download PDF through the admin panel in an order. I get an error that: Variable "companyInfo" does not exist

companyInfo is a global field - I am using it to populate the company invoice details like so; {{ companyInfo.companyName }} (there are several of these).

Any ideas why this is an issue on the back-end and not the front-end and how to resolve?

4

Since the templates are rendered on the server and not in a regular http request (in the front end templates), the globals are not loaded automatically, into the global twig namespace.

You can still access your global set and use it as you usually would by setting it to a variable. You can do so like this:

{% set companyInfo = craft.globals.getSetByHandle('companyInfo') %}

You can then do:

{{ companyInfo.fieldNameHere }}

  • Brilliant. Thanks Luke. I knew it would be something as simple as this. Just wasn't sure how/what. Thanks for clarifying. – Terry Upton Jan 4 '17 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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