Skip to Content

page.tpl.php Snippets

| | |
Printing out Individual Variables
<?php print $search_box ?>

Sometimes you will want/need to wrap the dynamic content in an appropriate parent element. In the case below, $head_title displays the title of the web site and the individual web page together as plain text. To make that text show in the browser chrome, you'll need to place the <?php print ?> tag in a <title> tag.

<title><?php print $head_title ?></title>
Basic PHP "if" Statements

The following statement means: If the $logo variable is enabled, show the code between the PHP tags.

<?php if ($logo) : ?>
  <img src="<?php print($logo) ?>" alt="Logo" />
<?php endif; ?>

The following statement means: If the $tabs variable does not equal nothing ("") do the following. In this case, print the code between the "if" and the "endif" PHP tags.

In other words, if the variable has no value or is not being used, do not show the code within the PHP tags.

<?php if ($tabs != ""): ?>
  <?php print $tabs ?>
<?php endif; ?>
Primary and Secondary Links
<?php if (count($primary_links)) : ?>
  <ul id="primary">
  <?php foreach ($primary_links as $link): ?>
    <li><?php print $link?></li>
  <?php endforeach; ?>
  </ul>
<?php endif; ?>

Replace every instance of the word "primary" above with "secondary" to create a list using the $secondary_links values

You'll find that almost every time you need to apply a theme variable you will use a combination of the above tags and syntax.