In this example we set an additional request to act as a theme. Using themes are useful when you want several web pages or requests to be displayed in a consistent look. A theme is only relevant when sending an HTML formatted response.
Test the example: http://kerkness.ca/kerkdemo/hello.galaxy
Example 3
Inside the folder kerk/modules/hello create a file called galaxy.php and add the following to it. This file is exactly the same as the universe.php file created in the first HTML example except we have added a line which sets the theme for our request. (note: We can still use the tempalte hello.universe even tho our request is hello.galaxy)
<?php
// Tell kerkness that this request should return an HTML response
$kerk->setResponseFormat('HTML');
// Set the template for this request
$kerk->setTemplate( 'hello.universe' );
// Set the theme for this request
$kerk->setTheme( 'hello.theme' );
// Add some content to the request object
$kerk->addContent('myVar', 'Hello Galaxy');
?>
Inside the directory kerk/modules/hello create the file ‘theme.php’ and add the following
<?php
$kerk->setTemplate('hello.theme');
$kerk->addContent('page_title', "This is my theme title");
?>
Inside the directory kerk/templates/hello create the file ‘theme.php’ and add the following
<html>
<body>
<h1><?php print $page_title ?></h1>
<!-- Place include tag where results from our main request will be placed -->
[include:main_request]
<h2>This is a footer</h2>
</body>
</html>
Now when you call http://kerkness.ca/kerkdemo/hello.galaxy the request hello.galaxy will now be displayed inside the hello.theme.
Next
Creating a full dynamic web page with several content blocks
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.