PEAR Manual
Prev |  | Next

# {if:variable}

{if:variable} -- creates a PHP if statement

## Synopsis

``Usage` ({if:variable}, {if:method()})`

## Description

creates an if statement, with the argument as a variable or method. You must close an if statement with an {end:} statement, and you may use {else:} with it.

## Example

Example 41-1. Setting variables for if
    class example {
        function showDog() {
            return true;
        }

        function output() {

            $this->showStuff = true;

            .........
            $template->outputObject($this);
        }
    }

Example 41-2. The template
    {if:showStuff}Hello{end:}
    {if:showDog()}Doggy{end:}

Example 41-3. Compiled template
    <?php if ($t->showStuff)  { ?>Hello<?php } ?>
    <?php if ($t->showDog()) {  ?>Doggy<?php } ?>

Example 41-4. The output
    Hello
    Doggy

Prev | Home | Next
{foreach:variable,key,value} | Up | {end:}