Feature Highlight: The GravityView [gvlogic] Shortcode

Feature Highlight: The [gvlogic] Shortcode

Written by Casey Burridge

Last updated:

Categories GravityView

Tags

In this edition of Feature Highlights, we’re homing in on GravityView’s powerful [gvlogic] shortcode. The [gvlogic] shortcode allows you to show/hide content based on user inputs, restrict content on your site to logged-in users, and much more!

If you’re new to GravityView, you’ll soon discover that it’s packed full of little gems that help to add new dimensions to your web applications. The [gvlogic] shortcode is one such gem, and we’re super excited to explore it with you here ​​💎

What Is the [gvlogic] Shortcode Used for?

The [gvlogic] shortcode allows you to construct conditional logic statements for displaying or hiding content on your website or within a View. (The shortcode works anywhere on your site!).

This allows you to:

  • Personalize email notifications and confirmation messages
  • Make your content “members only” by restricting it to logged-in users
  • Add dynamic content to your View layouts

Here’s an example of a basic conditional logic statement:

If {user_name} is “James”, display “Hi, James!”.

Now here’s the same statement but written using the [gvlogic] shortcode:

[gvlogic if=”{user_name}” is=”James”]
Hi, James!
[/gvlogic]

As you can see, the content we want to display goes between the opening and closing shortcode tags.

Shortcode Parameters

The [gvlogic] shortcode requires the following parameters:

  • if – (Required, unless you’re using the logged_in parameter. Accepts Gravity Forms Merge Tags)
  • logged_in – (Required, unless you’re using the if parameter)
  • is or equals – (Required if you’re using the if parameter)
  • else (What to display if the condition is not met)

The shortcode also accepts a range of comparison parameters such as greater-than, less_than, starts_with, ends_with, and much more.

When it comes to [gvlogic], there’s SO much you can do! We’ll briefly go through some of the most common uses cases below 👇

Showing/Hiding Content Based on User Inputs

The most common use case for [gvlogic] is showing/hiding content based on the values in a user’s submission. Here’s an example:

[gvlogic if="{favorite_food}" is="Pizza"]

Did you know that pizza was first invented in Naples, Italy as a fast and affordable snack for workers on the go? 🍕

[else if="{favorite_food}" is="Salad"]

The origin of salad can be traced back to the Romans, ancient Greeks and Persians, who all ate mixed greens with dressing 🥗

[else]

You need to choose a favorite food.

[/gvlogic]

As you can see, we can use the [else if] clause to string together various conditions based on certain criteria. This is helpful if you want to display different content depending on a user’s choice from a Select field.

💡 Pro tip: Gravity Forms has its own conditional shortcode. However, unlike the Gravity Forms shortcode, [gvlogic] supports AND/OR logic, nested shortcodes to check multiple conditions, and it integrates with GravityView.

Restricting Content on Your Website

You can use [gvlogic] to restrict content to logged-in users. This is handy if you run a member directory or a community site, and you want to hide certain content from regular site visitors.

To check if a user is logged in, use the logged_in parameter and set it to either “true” or “false”, like this:

[gvlogic logged_in="true"]
You are logged in, here’s some content!
[else]
Please log in first to view this content.
[/​gvlogic]

So, what if you want to add [gvlogic] to GravityView?

Displaying Content Conditionally Inside a View

Lastly, [gvlogic] also integrates with GravityView, allowing you to extend your web applications with content that displays dynamically depending on other data in your View.

To use [gvlogic] inside a View, simply add the shortcode to a Custom Content field. Here’s an example:

[gvlogic if="{Grade}" greater_than="75" else="Fail"]
Pass
[/gvlogic]

As you can see, the shortcode checks to see if the number in the “grade” column is greater or less than 75 and displays either “Pass” or “Fail”.

Start Exploring the [gvlogic] Shortcode

In this edition of Feature Highlights, we explored GravityView’s powerful [gvlogic] shortcode. Using [gvlogic], you can use conditional logic to show/hide content based on conditions that you set.

To learn more about the [gvlogic] shortcode, read our in-depth guide. To see more from our blog, subscribe to our newsletter below (we send out an email every two weeks packed full of our most helpful Gravity Forms content!).

Join Our Newsletter!📧🙌

✅ Helpful Gravity Forms content straight to your inbox

✅ Be the first to hear about new updates and releases