Create A New Page
How To Create A New Page
HTML pages within the codebase exist in 3 parts:
- The Page Logic - Like loading a list of all files for example. This is via a Controller, which then hands off to the template.
- The Template - Called a Twig template, but really it's mainly HTML.
- The Route - The URI used in the browser, like /your-page-name
You can see an example of the contact page parts.
- Page Logic - The contact() function within "\themes\spirit\controllers\IndexController.class.php"
- Template - The file "\themes\spirit\views\contact.html.twig"
- Route - See the registerRoutes() function within "\themes\spirit\ThemeSpirit.class.php"
Create A New PageWe'd recommend copying an existing page and editing as needed. The steps to create a new page from scratch are:
- Create the route entry within "\themes\spirit\ThemeSpirit.class.php". You'll need to set the route URI aswell as the class/method name on the line. Note these for the Controller later.
- Example:
$r->addRoute(['GET', 'POST'], '/my-page', '\themes\\'.$this->config['folder_name'].'\controllers\CustomController/myPage');
- Create a .html.twig file with your HTML in /themes/spirit/views/
- Note that this does not accept PHP code, only HTML.
- Create the controller entry by adding a controller file in /themes/spirit/controllers/, named for example CustomController.class.php
- Edit the file and ensure you've updated the class name also to CustomController.
- Add your method which will look something like this:
public function myPage() {
// load template
return $this->render('my_page.html', array(
'customVariable' => 'My Page',
));
}
- Ensure you purge the application cache via the script admin area after any changes to your site.