
Using the action handler and template we've made so far, now we're going to add in some PHP controlled content. Open your tpl-global.php file from before and change the contents to the following:
<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" /> </body> </html>
As you can see, we've added two vars sGen tags to the wrapper. To populate these variables, open your action handler and add the following before the print_page() call is made:
Serenity::output()->add_output( 'title', 'Hello World!' ); Serenity::output()->add_output( 'username', 'Bob' );
The add_output() call is chainable, so to save space you could write the above as:
Serenity::output()->add_output( 'title', 'Hello World!' )->add_output('username', 'Bob');
To recap, the sGen vars tag is mapped to the PHP call add_output(). You can add any number of vars to your HTML, there are no limits except what your machine can handle.
Taking this a step further, we'll now add some template bits to the wrapper.