Developer Area/Development Tutorials/Basic local static page

From Mahara Wiki
Jump to: navigation, search

Adding a "static pages" page

Sometimes you want to set up a page that doesn't change very often, like an information page, but still have the ability to tweak it via the admin interface. Static pages are for you. And if you are wanting to have this specific page be different for each institution you can do that too. but how do you add a "static page"?

Ok, to be able to add new local static pages you need to do the following steps

1. Add initial static page information

Static pages are driven from the database rather than being a static html file. So first we need to add some rows to the database to start us off.

In the database you need to add in records to the site_content table, eg:

 INSERT INTO site_content VALUES ('pageone', 'This is a site test', '2014-09-18 07:30:24', '2014-09-18 07:30:24', null, 'mahara');
 INSERT INTO site_content VALUES ('pagetwo', 'This is an institution test', '2014-09-18 07:30:24', '2014-09-18 07:30:24', null, 'testinstitution');

The 'pageone' is the internal name which Mahara will keep a track of

Note: the internal names for the pages can only be basic alphabet letters (no numbers or special chars)

set the last value to 'mahara' if you want it to be a site page otherwise set it to the internal name for the institution

But we can edit it yet, so

2. Add ability to select/edit new page from admin screen

In local/lib.php add the following code:

 function local_site_content_pages(){
    return array('pageone','pagetwo');
 };

where the array contains the internal names from step 1 that you want to be added to the select box on the admin screen.

Now you should see the option in the dropdown list on the admin 'static pages' edit screen (either site or institutional ones depending on what you set for step 1) but the display name for it will be broken - look like pageone/local - so

3. We need to define the language string

So we set up a file local/lang/en.utf8/local.php - you will probably need to make the directories as well - and add this to the new file

 <?php
 
 $string['pageone'] = 'Page One';
 $string['pagetwo'] = 'Page Two';
 ?>

If you are using languages other than english you will need to set up the local lang files for those languages as well eg local/lang/de.utf8/local.php for german, local/lang/fr.utf8/local.php for french, etc...

4. Getting your new static page to display

Copy the following code into a file and save that file into the local dir, eg local/pageone.php (so that later you can hit http://yourmaharasite.com/local/pageone.php to view the page)

 <?php
 define('INTERNAL', 1);
 define('PUBLIC', 1);
 require('../init.php');
 define('TITLE', get_string('pageone'));
 
 $smarty = smarty();
 $smarty->assign('page_content', get_site_page_content('pageone'));
 $smarty->display('sitepage.tpl');
 
 ?>

If you are wanting the page to only be for logged in users remove the line: define('PUBLIC', 1);