The Template File
Step 8 – Outputting dynamic data in your template file
While still in the page editor from step 7, click the "View" link to see your page. Note that it still says "Happy planet" for type (rather than "Terrestrial planet") and "Millions of years" rather than "4.54 billion years". That's because the page is still being rendered with just the static data in it. We need to update the template file so that it recognizes the fields we added and outputs the values of those fields.
Edit /site/templates/planet.php and replace the static text in there with tags like this, replacing
field_name with the name of the field:
<?php echo $page->field_name; ?>
If supported by your server, you may also use this shorter format which some people find easier to look at and faster to enter:
Here is the /site/templates/planet.php file updated to output the content of the page using tags like the above:
<html> <head> <title><?php echo
$page->title; ?></title> </head> <body> <h1><?php echo $page->title; ?></h1> <h2> Type: <?php echo $page->planet_type; ?>, Age: <?php echo $page->planet_age; ?> years </h2> <p><?php echo $page->planet_summary; ?></p> </body> </html>
After making these changes, save your planet.php template file. Now view your Earth page again. You should see it properly outputting all of the content you entered on the page, including "Terrestrial planet" for Type and "4.54 billion years" for age. Any changes you make from this point forward should be reflected in the output.
Next: More Pages »
- Introduction and First Steps
- Create a Template and a Page
- Setting up Custom Fields
- The Template File
- More Pages
Your e-mail is kept confidential and not included with your comment. Website is optional.