---
title: "Feature Highlight: The [gvlogic] Shortcode"
date: 2022-05-10
author: "Casey Burridge"
link: "https://www.gravitykit.com/gvlogic/"
---

# Feature Highlight: The [gvlogic] Shortcode

In this edition of [Feature Highlights](https://www.gravitykit.com/tag/feature-highlight), 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](https://www.gravitykit.com/features/), 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  Shortcode Used for?

The `[gvlogic]` shortcode allows you to construct [conditional logic](https://www.gravitykit.com/gravity-forms-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](https://www.gravitykit.com/gravity-forms-confirmations/)
- 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](https://www.gravitykit.com/shortcode-hide-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](https://www.gravitykit.com/gravity-forms-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](https://www.gravitykit.com/custom-content-field/). Here’s an example:

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

![](https://www.gravitykit.com/wp-content/uploads/2022/05/image-19.png)
*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  Shortcode

In this edition of [Feature Highlights](https://www.gravitykit.com/tag/feature-highlight/), 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](https://www.gravitykit.com/gravity-forms-conditional-logic-gvlogic/). To see more from our [blog](https://www.gravitykit.com), subscribe to our newsletter below (we send out an email every two weeks packed full of our most helpful Gravity Forms content!).