How can I hide parts of a page?

Hiding parts of a page or displaying them only when a condition occured is quite easy. Just take a look at the following example:

001    <patTemplate:tmpl name="page">
002          <html>
003                <head>
004                      <title>patTemplate Example</title>
005                </head>
006                <body>
007                      <!-- This template is hidden by default -->
008                      <patTemplate:tmpl name="secret" visibility="hidden">
009                            I know a secret:
010                            <b>Clark Kent is superman!</b>
011                      </patTemplate:tmpl>
012                </body>
013          </html>
014    </patTemplate:tmpl>

This example consists of two templates: page and secret, which will not be displayed if you call displayParsedTemplate() after loading this templates. It will not be displayed because of the visibility="hidden" attribute.
If you went to display the page template, including the secret template, you may do this by using a PHP method of the patTemplate class called setAttribute. This method takes three arguments, the first is the name of the template for which the attribute should be set. The second is the name of the attribute and the last is the value of the attribute.

To change the visibility of a template, use the follwing PHP code:

1        <?PHP
2        $tmpl->readTemplatesFromFile( "myTemplate.tmpl" );
4        if( $knowSecret == "yes" )
5          $tmpl->setAttribute( "secret", "visibility", "visible" );
7        $tmpl->displayParsedTemplate( "page" );
8        ?>


Hiding a template
To hide a template, which is displayed by default, set the visibility attribute to hidden.