Documentation Menu

1.5 Template Project

The Joomla! Documentation Working Group is running a project to develop detailed reference and tutorial material on Joomla! 1.5 templates.  There is a project page on the documentation wiki where you can see the work in progress and help us by contributing your knowledge.

Who's Online

We have 5 guests online

Help Site License

The Joomla! Help Site content is copyright © 2005 - 2008 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution NonCommercial ShareAlike 2.5. Some parts of this website may be subject to other licenses.
Home arrow patTemplate arrow Freqently Asked Questions arrow How can I hide parts of a page?

How can I hide parts of a page? PDF Print E-mail

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.

< Prev   Next >