Page layout
Create site21 by copying site20.
- /cms
- ...
- site20
- site21
In this chapter, we are going to create a direct access to a node in a default thread with a specific page layout.
To test the result online, enter http://www.frasq.org/cms/site21/en in the address bar of your navigator. Click on the link Legal information in the footer of the home page. The site displays the content of node 1 of thread 1 with a simple page layout.
Create the action page
by adding the file page.php in the folder actions with the following content:
- /cms/site21
- actions
- page.php
- actions
- require_once 'models/thread.inc';
- function page($lang, $arglist=false) {
- $page=false;
- if (is_array($arglist)) {
- if (isset($arglist[0])) {
- $page=$arglist[0];
- }
- }
- if (!$page) {
- return run('error/notfound', $lang);
- }
- $thread_id = 1;
- $page_id = thread_node_id($thread_id, $page);
- if (!$page_id) {
- return run('error/notfound', $lang);
- }
- $r = thread_get_node($lang, $thread_id, $page_id);
- if (!$r) {
- return run('error/notfound', $lang);
- }
- extract($r); /* node_name node_title node_abstract node_cloud node_nocomment */
- $page_name=$node_name;
- $page_title=$node_title;
- $page_abstract=$node_abstract;
- $page_cloud=$node_cloud;
- $page_contents = build('nodecontent', $lang, $page_id);
- head('title', $page_title);
- head('description', $page_abstract);
- head('keywords', $page_cloud);
- $validate='/' . $lang . '/'. $page_name;
- $banner = build('banner', $lang, compact('validate'));
- $content = view('page', false, compact('page_name', 'page_title', 'page_contents'));
- $output = layout('standard', compact('banner', 'content'));
- return $output;
- }
Notice that the page
action looks for nodes in the thread 1.
Give access to the page
action by adding an alias for each language in the file includes/aliases.inc:
- 'page' => 'page',
- 'page' => 'page',
Since the view doesn't depend on the language, put it directly in the folder views:
- /cms/site21
- views
- page.phtml
- views
- <h3><?php echo htmlspecialchars($page_title, ENT_COMPAT, 'UTF-8'); ?></h3>
- <?php
- if ($page_contents) {
- echo $page_contents;
- }
- ?>
Add the function thread_get_node
in the file models/thread.inc:
- function thread_get_node($lang, $thread_id, $node_id) {
- $sqllang=db_sql_arg($lang, false);
- $tabthreadnode=db_prefix_table('thread_node');
- $tabnode=db_prefix_table('node');
- $tabnodelocale=db_prefix_table('node_locale');
- $sql="SELECT tn.number AS node_number, nl.name AS node_name, nl.title AS node_title, nl.abstract AS node_abstract, nl.cloud AS node_cloud FROM $tabthreadnode tn JOIN $tabnode n ON n.node_id=tn.node_id JOIN $tabnodelocale nl ON nl.node_id=tn.node_id AND nl.locale=$sqllang WHERE tn.thread_id=$thread_id AND tn.node_id=$node_id LIMIT 1";
- $r = db_query($sql);
- return $r ? $r[0] : false;
- }
thread_get_node
returns all the attributes for the language $lang
of the node whose identifier is $node_id
which is in the thread whose identifier is $thread_id
, or false
in case of error.
Enter http://local.frasq.org/cms/site21/en/page/legal-information in the address bar of your navigator. Try the version in French at the address http://localhost/cms/site21/fr/page/informations-legales.
Modify how a URL is analyzed in the route
function defined in the file library/engine.php so the page
action become the default action:
- return array('page', $args);
The last step consists in adding a link to the footer.
- /cms/site21
- views
- en
- footer.phtml
- fr
- footer.phtml
- en
- views
Enter http://localhost/cms/site21/en in the address bar of your navigator. Click on the link Legal information in the footer. Check the version in French.
Comments