Keep up to date with Gravity PDF

  • This field is for validation purposes and should be left unchanged.

Introduction #introduction

Gravity Forms has a powerful marco they call Merge Tags which allows you to display form content, user meta data, post data and other information like the entry submission date. There’s also conditional shortcodes which you can use to allow simple IF statements. Both merge tags and conditional shortcodes are supported in PDF templates and together they make a powerful combination.

Template Tutorial – Part 2 #template-tutorial

The Hello World Gravity Form

In Template Tutorial – Part 1 we showed you the very minimum needed to create a PDF template. In part 2 we’re going to utilise merge tags and conditional shortcodes in a template. Before you begin you will need to download the Gravity Form (right click and ‘save link as’) we’ll be working with and import it into your website. Once done, submit a new entry for the newly-imported Hello World form.

Merge Tags #mergetags

Mergetags in the Gravity Form notification

Gravity Form field merge tags use the format {[Field Name]:[field_id]}. Keep in mind, the Field Name isn’t required and advanced fields have a slightly different format.

When you first start using merge tags, the simplest way to write them is by editing one of your form’s notifications and then using the merge tag selector to the right of the Message field. Just copy and paste the merge tag to your PDF template.

Once you’re comfortable with how certain fields are formatted it becomes easy to write your own: {Email:5}, {:5}, {First Name:4.3} or {:4.3}.

In our hello-world.php template we’re going to add a new line below the <h1> tag and include our form’s merge tags:

<h1>Hello World</h1>

<p>You're from {Where do you live?:3}, {Name (First):1.3}? How cool is that!</p>

Now when you view the Hello World PDF for the entry you created earlier it will include the Gravity Forms data. All Gravity Form fields can be displayed in the PDF this way.

Conditional Shortcodes #conditional-shortcodes

Conditional Shortcodes allow you to output different content in the PDF based on a user’s response. The structure of the shortcode is relatively simple, with four required attributes including: action, merge_tag, condition and value. See the Gravity Forms documentation for full details on its usage.

When your value contains any of the following characters <, >, ", ' or & you’ll need to use the WordPress function esc_html() to get the desired result.
Example: condition="is" value="<?php echo esc_html( 'Honey & Spice' ); ?>"] ...

In our hello-world.php template we’re going to add conditional shortcodes that outputs a small fact about where the user lives. If a user selects Earth only the Earth fact will be displayed. Below the line we just added we’ll include the following:

<p>You're from {Where do you live?:3}, {Name (First):1.3}? How cool is that!</p>

When you view the Hello World PDF now it will conditionally display one of the four facts. Then edit the Hello World entry and changing the Where do you live? field value. When you view the PDF again a different fact will be displayed.

Download the completed Hello World PDF template for Part 2.

Signup for the latest Gravity PDF news, tips and updates

  • This field is for validation purposes and should be left unchanged.
Scroll To Top

Choose your currency:

Converted prices are for reference only - all orders are charged in $ Australian Dollars ($) AUD.
  • AUDAustralian Dollars ($)
  • USDUS Dollars ($)
  • CADCanadian Dollars ($)
  • EUREuros (€)
  • GBPPound Sterling (£)
  • NZDNew Zealand Dollar ($)
  • JPYJapanese Yen (¥)