Skip to content

Add a new page

Carina aka Neko Cari edited this page May 6, 2023 · 2 revisions

Add a new Page

Depending on your needs, there are 2 possibilities to add your custom page, since version 1.2.

Variant A (only version 1.2. or higher)

  • for simple rendering of a view
  • no unique routing identifier will be available

Variant B

  • more complex pages, where you would want to use a controller for programming logic
  • create a unique routing identifier to use for linking

Variant A

Follow these steps to add a new page

  1. Put your new file somewhere in the /app/views/(lang)/pages folder.
    Note, that each language has it's own sub folder! So most importantly add it in your main language, since it is used as a fallback.
    Include just the content of your page. The application will add the header and footer template.

  2. Link to your new Page
    Your page can be accessed when entering (yoururl.com)/pages/(yourfilename).php in your browser. And that's the URL you can link to.

IMPORTANT This only works for files you put in the pages subfolder!

Variant B

Follow these steps to add a new page

  1. Put your new file somewhere in the /app/views folder.
    Note, that each language has it's own sub folder! So most importantly add it in your main language, since it is used as a fallback.
    Include just the content of your page. The application will add the header and footer template.

  2. Add a new method in a controller class file, e.g. /app/controllers/pages.php, which is mostly intended for static pages. In this file you'll find a template method at the bottom for you to copy, paste and edit, or you can copy it from here:
    public function action() { Layout::render('folder_within_views/your_page.php'); }

    • change action to be a unique method name within the class file
    • change the path folder_within_views/your_page.php so it points to your file within the views folder.
      Instead of app/views/en/folder/page.php simply write folder/page.php.
  3. Add a new route

    • v0.1
      Open /routing.php. Within the file you'll also find this example code, with explanation.
      Routes::addRoute('IDENTIFIER','URL','controller','action');

      • IDENTIFIER is the key which is used for links and has to be unique
      • URL is the address you enter in your browser, to view the page
      • controller is the name of the class in lowercase, you added your action to, in step 2.
      • action is the method name you chose in step 2.
    • v1.0 and higher
      Login to the app as an admin and go to administration > application > routing. Add a new route and set the following values:

      • Identifier is the key which is used for links and has to be unique
      • URL in browser is the address you enter in your browser, to view the page
      • Controller Class Name is the name of the class, you added your method to, in step 2. This field is case-sensitive!
      • Method within Controller is the method name you chose in step 2.
      • Request Method choose between get, post or get|post. Get enables the page to be accessed directly by entering the URL in the browser address field. Post enables it, so you can send form data to it. By choosing get|post it enables both.

If everything is set up correctly, you should be able to access your new page using set URL.

  1. Link to your new page

To link to your page you can use ROUTES::getUri('IDENTIFIER'); which returns the URL, so you can change it in the routing settings later on, without having to update your links manually.

Clone this wiki locally