Merge Tag Modifiers

Merge Tag Modifiers

Introduced in Version 1.17

GravityView heavily uses Gravity Forms Merge Tags; they're very powerful.

To enhance Merge Tags, GravityView adds additional "modifiers" that allow you to format Merge Tags differently.

GravityView Modifiers:

  • :wpautop - Runs wpautop() on the output
  • :maxwords:{number} - Limit output to {number} of words
  • :timestamp - Convert Date field to a timestamp

Note: These modifiers will not be processed on {all_fields} Merge Tags.

Usage: :wpautop modifier

The wpautop modifier changes double line-breaks in the text into HTML paragraphs (<p>...</p>) and single line-breaks are converted to HTML <br />. Line breaks within script and style sections are not affected.

This modifier will run the wpautop() function on the Merge Tag's content. Learn more on WordPress.org.

Before: 

  • Merge Tag: {Cosmonaut:4}
  • Output: The Earth was small and light blue.

After: 

  • Merge Tag: {Cosmonaut:4:wpautop}
  • Output: <p>The Earth was small and light blue.</p>

Usage: :maxwords:{number} modifier

Limits the length of displayed field content to {number} words.

When the content length exceeds the number of words, "…" will be appended to the text. Example: "The text is too long" becomes "The text…".

How to display the first 10 words of a testimonial.

We have a form named "Testimonial", where we gather feedback from customers. It has a textarea field named "Quote", and it has the field ID of "12".

To display the content in GravityView, we normally us the {Quote:12} Merge Tag. The full quote is too long, though:

I really enjoyed the service that I received. Thank you for all your help! In the future, I will have no reservations about referring people to your business. Thanks again!

That quote has 30 words. We only want to show the first 10 words so the content fits nicely in our heading. We can use the maxwords modifier to limit the number of words.

We can add the maxwords "modifier" to the end of the Merge Tag, along with the max number of words we want: :maxwords:10. The final Merge Tag looks like {Quote:12:maxwords:10}.

Here's the output from the {Quote:12:maxwords:10} Merge Tag:

I really enjoyed the service that I received. Thank you…

Notes:

  • Commas, periods, etc, connected to the final word of the value will be preserved.
    • If you set maxwords:3 on this value: Example with comma, to be trimmed, the output would be Example with comma,&hellip;
  • HTML tags are preserved
    Whitespace between tags will make an HTML tag be considered a separate word:
    • <p> <strong>Example</strong></p> Will be considered two words because there is a space between <p> and <strong>.
    • <p><strong>Example</strong></p> Will be considered one word.
  • HTML entities are allowed
    If they are separated by word breaks, they will be counted as words:
    • Foo & Bar will be considered three words because & is separate
    • Foo& Bar will be considered two words because & is connected to Foo
  • When the text is truncated, "…" is appended to the output, using HTML entity &hellip;

Usage: :timestamp modifier

The timestamp modifier converts valid dates into a timestamp (the number of seconds since the Unix Epoch, January 1 1970 00:00:00 GMT). This is helpful for use in combination with the [gvlogic] shortcode.

This modifier will run the strtotime() function on the Merge Tag's content. If not a valid format, the value will be returned as -1.

Before: 

  • Merge Tag: {Date:3}
  • Output: 07/07/2003

After: 

  • Merge Tag: {Date:3:timestamp}
  • Output: 1057547880

It will work with any format for the Date field ( mm/dd/yyyy, yyyy-dd-mm, and everything in between):

Before: 

  • Merge Tag: {Text Field With Parseable Date:6}
  • Output: July 14, 2015, 11:49 GMT

After: 

  • Merge Tag: {Text Field With Parseable Date:6:timestamp}
  • Output: 1436874540

Notes:

  • The timestamp modifier is designed to work with Date fields, but it will work for any field, as long as the value is formatted in a way that is parsed by PHP's strtotime() function.