{feature}

Renders its content while a feature flag is on for this visitor, and its else half while it is off.

Users and access Tag pairs

Syntax

{feature 'flag'} ... {/feature}
{feature 'flag'} ... {else} ... {/feature}

Parameters

flag
A name in $padFeatures: TRUE, FALSE, a share from 0 to 1 of the visitors, or the name of a function given the user.

Description

{feature 'search2'} renders its content while the flag is on for this visitor, and the part after its own {else} - or the @else@ half - while it is off. The flags are the setting $padFeatures, normally in _config/config.php, name => what decides it:

  • TRUE or FALSE - on or off for everybody;
  • a number from 0 to 1 - on for that share of the visitors, decided per visitor and the same on every visit: by a hash of the flag's name and the user's id, or for a guest a random id in a long-lived padFeatureId cookie;
  • the name of a function - called with the user's row (NULL for a guest).

padFeatureOverride ( 'search2', TRUE ) fixes a flag for the rest of the request, whatever the setting says - for a test or a preview - and padFeature ( 'search2' ) asks from PHP. A name that is no flag is FALSE and, under the strict check, an error.

A share depends on the visitor, so that example is shown, not run.

Examples

A flag on and a flag off

TRUE and FALSE in $padFeatures switch a part for everybody - normally set in _config/config.php.

Templateexamples/feature/1-on-off.pad
{feature 'newSearch'}
  <p>The new search, with suggestions.</p>
{else}
  <p>The old search.</p>
{/feature}
{feature 'darkMode'}
  <p>Dark mode is on.</p>
@else@
  <p>Dark mode is not released yet.</p>
{/feature}
PHPexamples/feature/1-on-off.php
<?php

  $padFeatures = [ 'newSearch' => TRUE, 'darkMode' => FALSE ];

?>
Resultopen alone

The new search, with suggestions.

Dark mode is not released yet.

Fixed for a test

padFeatureOverride fixes a flag for the rest of the request - a test or a preview - whatever $padFeatures says.

Templateexamples/feature/2-override.pad
{feature 'checkout2'}
  <a class="button" href="#checkout2">Pay in one step</a>
{else}
  <a class="button" href="#checkout">Go to the checkout</a>
{/feature}
PHPexamples/feature/2-override.php
<?php

  padFeatureOverride ( 'checkout2', TRUE );

?>

A share of the visitors

0.25 is on for a quarter of the visitors - decided per user, or per a long-lived cookie, and the same on every visit.

Templateexamples/feature/3-share.src
{# _config/config.php: $padFeatures = [ 'search2' => 0.25, 'beta' => 'isBetaTester' ]; #}
{feature 'search2'}
  <form action="?search2">...</form>
{else}
  <form action="?search">...</form>
{/feature}
{feature 'beta'}<p>Thanks for testing the beta.</p>{/feature}

See also

  • {can} Renders its content when the user may do something a gate decides, and its else half when not.
  • {auth} Renders its content when a user is logged in, with the user's row as its data, and its else half for a guest.
  • {if} Renders its content only when a condition holds, with elseif and else branches.