Skip to content

Creating website pages

Ricky edited this page Feb 21, 2022 · 3 revisions

The website referred to in this documentation sits on top of HamletCMS, you cannot create content for it directly through the CMS (without writing code to pull the content through). HamletCMS comes with a boilerplate site module within the core codebase /app/modules/core/Website. This should be overridden with your own using an addon module as follows:

Getting started creating a custom website module

  1. Copy the module in /app/modules/core/Website into /app/modules/addon/MyWebsite
  2. Correct the namespace in /app/modules/addon/MyWebsite/controller/Site.php
  3. Update config/config.json file, under environment set "site_controller": "\\HamletCMS\\MyWebsite\\controller\\Site"
  4. Update the home function in Site.php as required

Adding new pages

  1. Add a public function to your Site controller
  2. Name the function the same as the url path - so for an about page (example.com/about) the function should be called 'about'
  3. Note: the terms 'blogs', 'cms' and 'api' are already used so don't use them!
  4. Call $this->response->write('<template-path>', 'MyWebsite'); to output a smarty file (see full response documentation)
  5. Create the smarty template file under /app/modules/addon/MyWebsite/templates
  6. Note: by default semantic UI is included

Using this site controller gives you chance to use the HamletCMS model to query blog data and display on the website as you feel fit as well as providing a simple routing system for clean URLs.