corporate » labs » forge
E29 Incorporated

E29 Product Documentation


sGen: Loading and printing template files

Given the size and complexity of most web applications, editing and maintaining thousands of pages worth of HTML isn't appealing. Like most template layers, sGen supports including template bits inside the wrapper, and inside of other template bits. A sGen template bit works just like the wrapper in that you can use any sGen tag inside the bit, and it will be parsed just like the wrapper itself.

To get started, open up the tpl-global.php file that we've been working with, and change the contents to the below:

<html>
<head><title><sgen vars="title" /></title>
<link rel="stylesheet" href="<sgen config="style_path" />/style.css" type="text/css" />
</head>
<body>
This is the in the wrapper: <sgen vars="username" />
<sgen bits="body_content" />
</body>
</html>

This time we've added the sGen bits tag to the template, which will allow us to insert another template at that location.

Before we alter the action handler, create a new template file:

/cache/style/$YOUR_APP_KEY/tpl-main_body.php

And insert some random content, such as 'HAI GUYS' in the template file. Now open the action handler and add the following function call somewhere before the print_page() call:

Serenity::output()->load_template( 'body_content', 'main_body' );

Save, refresh, and your content will be displayed. Keep in mind that when working with the load_template() call, the 2nd argument is the name of the template file you created in the style folder, minus the tpl- part and the extension. However, sGen template files are required to be prefixed with tpl-, and end in the PHP extension.

As mentioned before, you can use any sGen tag inside a template bit as if it were the wrapper itself. Add some dynamic content from the previous article and give it a spin!

Next, we'll tackle outputting dynamic data from a database call or array.

 
developers/tutorials/serenity/sgen-templates.html.txt · Last modified: 2008/07/24 13:53 by akinder