Article

  • 3 years

    2 years

    YetiShare / Core

    2250

Create A New Page

How To Create A New Page

HTML pages within the codebase exist in 3 parts:

  1. The Page Logic - Like loading a list of all files for example. This is via a Controller, which then hands off to the template.
  2. The Template - Called a Twig template, but really it's mainly HTML.
  3. The Route - The URI used in the browser, like /your-page-name

You can see an example of the contact page parts.

  1. Page Logic - The contact() function within "\themes\spirit\controllers\IndexController.class.php"
  2. Template - The file "\themes\spirit\views\contact.html.twig"
  3. Route - See the registerRoutes() function within "\themes\spirit\ThemeSpirit.class.php"

Create A New Page

We'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.