Skip to toolbar

The [if][else][/if] conditional block gives added functionality to your Pods Templates by giving you the ability to use simple “if this exists, display this, else do this instead” logic.

The previous example illustrating an each for a relationship field, has a major problem: if there are no chapters set it would output:

IF Check against Related or LOOP Content

To avoid, this the each loop can be placed inside of if conditionals, so that nothing is outputted if there are no chapters to output:

You could use this same methodology before looping through connected Taxonomy, File/Image Fields or Relationships

IF using ELSE Example

Now there will be no output if there are no related chapters to return. You can even take this a step further by adding alternate output, if the conditional is not met, using an else statement. For example:

IF Check Against a Field

If conditionals are also useful when you wish to show a label before a field, but do not want that label to appear if the field has no value. In the following example, the text “Co Author:” only appears if there is a value in the ‘co_author’ field.

The IF check against a field only checks for the existence of content in the field. You can’t do complicated matching or any kind of AND/OR conditions.

Note: The IF template tags are unable to do exact matching like [if field="something"] within the block. If you need to match something specific, use PHP Theme Templates.