
The only required sGen template file is the wrapper. In the previous article, we created the tpl-global.php file under /cache/style/$YOUR_APP_KEY/. This file is what sGen considers the 'wrapper'. Generally any consistent headers, footers, menus, or CSS information would be placed in this file.
Although the wrapper file has a PHP extension, no PHP code should be placed in these files. PHP code is not parsed or executed in the templates, if you need to execute PHP code or gain access to variables in Serenity, you'll need to create a sgen.parse plugin, as explained later.
For now, let's create a simple page that loads an external CSS file. First create the CSS file in the following location:
/cache/style/$YOUR_APP_KEY/style.css
Now open tpl-global.php and add the following HTML:
<html> <head><title>Hello World!</title> <link rel="stylesheet" href="<sgen config="style_path" />/style.css" type="text/css" /> </head> <body> Hello Body! </body> </html>
Here we have the first example of sGen's tag library. ( In this tutorial anyway ). The style_path configuration variable helps map the URL to your application's theme directory. We'll set this up in the action handler below.
Open your default action handler ( again, if you are lost, refer to the Hello World tutorial series ) and set the style directory as so:
<?php class App implements serenity_application { public function App() { // // Go for it Serenity::output()->set_style_dir( "/app_hello" ); } } ?>
Substitute out /app_hello with whatever your application key is, prefixed with a slash.
Now that sGen understands where to find the theme information, let's load the wrapper. Add the following line after the set_style_dir() call:
Serenity::output()->load_wrapper( 'app_hello' );
Again, substituting out app_hello for your application key. The last function call needed to display the page is print_page(). Add it below the load_wrapper() call:
Serenity::output()->print_page();
So your action handler should look like this:
<?php class App implements serenity_application { public function App() { // // Go for it Serenity::output()->set_style_dir( "/app_hello" ); Serenity::output()->load_wrapper('app_hello'); Serenity::output()->print_page(); } } ?>
Save and refresh, and you will see the HTML outputted, with the proper URL placed where the config tag used to be.
There are other configuration tags available, those are listed on the sGen API document (NOTE: we're still working on the sGen API docs
Taking this base, we'll move on to add in dynamic content using the var tag.