
sGen started as the Style Generator Engine in 2001. It's first iteration was as a simple template engine for a project, and evolved from there.
Today it is arguably one of the most powerful and robust style engines for PHP. The template syntax follows a logical XHTML style, and the engine is wrapped into Serenity so that you can easily share dynamic data and even database returns with HTML without cluttering the web page with PHP markup.
To get started with our small application, you'll need to create a main wrapper for app_hello. Start by creating the template directory for app_hello under the style/ cache:
/path/to/server/htdocs/cache/style/app_hello
Now create a template file inside style/app_hello/ called tpl-global.php containing the following:
<html> <head> <title>My First Application</title> </head> <body> Hello world! </body> </html>
Going back to our index action handler, open the PHP file ( /path/htdocs/applications/app_hello/app_index.php ) and replace your print line with the following:
Serenity::output()->load_wrapper('app_hello'); Serenity::output()->print_page();
Save and refresh the page. You will still see Hello World!, however this time it's being generated via the style engine.
Still a bit boring, so instead of putting Hello World in the template page, replace it with the following tag:
<sgen vars="hello" />
Going back to our index action handler, add the following right above Serenity::output()→print_page();:
Serenity::output()->add_output( 'hello', 'Hello SerenityAP!' );
Do the save;refresh routine, and now Hello SerenityAP! will be displayed, althought this time 100% dynamically.
sGen has much more to offer, but for now, let's work on serving content from a database.
Next up: Hello Database!