By Stephen Walker

Conditional rendering – Oh the power

Share

In version 7.3 the ThemeFusion team added conditional rendering to the Avada toolset, but what they didn’t do is explain all of the possible use cases. The initial focus in on Woo-commerce, user roles, and as a replacement for the visibility settings on device types. Even their overview only gives you a basic glimpse into the power. In a couple of projects at work I have discovered how powerful they can be especially combined with custom fields and dynamic data. The one drawback is that it is limited to columns — standard and nested — and containers, but nested columns are really the key at this point.

Rendering based on an empty value

Scenario 1 : Subtitle

The first time I ran across an undocumented feature is when I was working on a blog layout. In this design I have the excerpt text displayed below the title of a post, but I also have a custom field for a subtitle. The latter is seldom used, but when it is I don’t want both the subtitle and the excerpt to show. I was thinking, it would be really nice if the dynamic element allowed me to have a fallback of the excerpt. While this may be possible since the before and after fields can use Avada shortcodes, I haven’t tested it in the fallback. As I looked at the screen I started thinking about conditional rendering and would it be possible to have an if-then condition — if the subtile is null, show the excerpt. What I found is that you can do just that — if the custom field “subtitle” is empty. Since the dynamic data for the subtitle has a fallback of nothing, it is not displayed by default. I built a custom title bar and placed each element into its own nested column.

The steps

Fortunately, this is really simple to build.

screenshot of the conditional rendering interface
  1. Open the conditional rendering logic options and choose custom field
  2. Add the custom field ID
  3. Leave the value field blank

Scenario 2: Special Label

The scenario and setup is essentially the same as the previous with only one small variation. In this case we need to display that an official biography is only available for historic purposes and that the person is no longer part of the organization. I have a set of custom fields for a biography that include a start year and an end year. While the person is with the company, the end year is blank and has a fallback of “present.” When the individual departs, the departure year is added. In this scenario the condition is set to render when the custom field “departure_year” is not equal to blank. I could have added a checkbox field with a set value, but this minimizes the need to update two field when a person departs.

Title bar showing added label

This is just the beginning of my exploration of the conditional rendering logic and I expect in the near future that these features will be expanded to allow even more options.

Originally published on June 24, 2022

Most Advanced WordPress Form Builder

2 Comments

  1. louisecuschieri November 14, 2022 at 4:49 am - Reply

    Thank you! I so need this to work for my application of “if there’s no featured image in the blog post, display an ACF field with a video link instead”. I don’t think this is possible yet as there is no condition type for featured image. :(

    • Stephen Walker November 14, 2022 at 5:00 am - Reply

      The conditional rendering is currently limited to containers and columns. They are planning to extend this capability and you can vote on it (https://theme-fusion.com/engage/feature-voting/). The solution for what you want is to place the image element and the video element in their own nested columns and then show or hide based on the presence of the video url.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

RELATED ARTICLES

  • New Links Catalog

    Instead of continuing to add to the footer, I decided to create a links page that will allow me to add unlimited links, categories them, and with the use of wpGridBuilder, create a faceted filtering capability.

  • The Case of the Strange Gap

    If you are new to Avada there are some defaults that can trip you up. Page content padding is one of those, but as always, very easy to overcome.

  • Calling for Input

    I am working on my 2023 publishing schedule and want your feedback. Please submit ideas for new posts, demos, and videos.

  • To Avada, or not to Avada (Winter 2022)

    Oh no, not again. Every few months, I find new reasons to like and dislike Avada. This is just the latest installment.

  • Avada Website Showcase

    I added an Avada Showcase to allow others to share their websites. The goal is to inform and inspire others on the power of the Avada Website Builder

  • Auto Formatting Dashes and a Workaround

    In case you didn't know it, WordPress has a couple of built-in auto-formatting features that are really helpful --- the em dash and the en dash.