Mecha CMS

Add extra functionality to the core engine.

Page

Table of Contents
  1. Page 
  2. Data 
  3. Child 
  4. Conditions 

Convert file and folder structure into web pages.

This extension activates the basic features of a website by utilizing the structure of the page file placement in the .\lot\page folder. This extension also adds some useful properties to the $site variable.

Page 

What is a page?

Page is a plain text file stored in the .\lot\page folder. The correct file name format for the page is composed of characters a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and -.

.\
└── lot\
    └── page\
        ├── lorem-ipsum.page
        ├── dolor-sit.page
        └── no-no-no.page

A .page extension is the default file extension for page files to state that the page is active and publicly available. There are several other page file extensions that can also be used:

  • .page → Available publicly and will appears together in the public page list.
  • .archive → Available publicly but will not appears together in the public page list.
  • .draft → Not available publicly and will not appears together in the public page list.

To read .\lot\page\lorem-ipsum.page from the site, visit https://mecha-cms.com/lorem-ipsum.

A minimal page file content consists of a text. Any text. With optional header data written in a YAML syntax:

---
title: Page Title
description: Page description.
type: HTML
...

<p>This page content is valid.</p>
<p>This page content is also valid.</p>

Any missing header data will be replaced by default data that is generated automatically by the engine. Let’s say that the default data will be loaded at first, and then it will be overwritten by the header data of the current page. Most of the default data are just an empty string or null, which can also be evaluated to boolean false in most cases.

return [
    'x' => [
        'page' => [
            'page' => [
                'title' => null,
                'description' => null,
                'author' => null,
                'type' => 'Markdown'
            ]
        ]
    ]
]

A page file can also have connections to other files through a folder that has the same name as the page name.

.\
└── lot\
    └── page\
        ├── lorem-ipsum\
        ├── lorem-ipsum.page
        ├── dolor-sit.page
        └── no-no-no.page

Users can store other data that has relationship with the page file in that folder. If the file name ends with extension .data, then this file will act as an external page property. This is called Data.

Data 

Data has a higher priority than internal header data. So, if you have a title.data file in the .\lot\page\lorem-ipsum folder, then the contents of that file will overwrite the title property written in the page file.

.\
└── lot\
    └── page\
        ├── lorem-ipsum\
        │   ├── title.data
        │   ├── description.data
        │   └── author.data
        ├── lorem-ipsum.page
        ├── dolor-sit.page
        └── no-no-no.page

Users can also add other page files in the folder as well. This, can then be named as Child.

Child 

Child will overwrite the page view of the current file, and will change the page view into a list of page children.

.\
└── lot\
    └── page\
        ├── lorem-ipsum\
        │   ├── title.data
        │   ├── description.data
        │   ├── author.data
        │   ├── lorem-ipsum-child-1.page
        │   ├── lorem-ipsum-child-2.page
        │   └── lorem-ipsum-child-3.page
        ├── lorem-ipsum.page
        ├── dolor-sit.page
        └── no-no-no.page

Note: To ask the engine to disable the page listing view in a particular folder, put an empty file with name .page or .archive in the folder.

// Before
.\lot\page\lorem-ipsum\
.\lot\page\lorem-ipsum.page

// After
.\lot\page\lorem-ipsum\.page
.\lot\page\lorem-ipsum.page

And so on…

.\
└── lot\
    └── page\
        ├── lorem-ipsum\
        │   ├── lorem-ipsum-child-1\
        │   │   ├── title.data
        │   │   ├── description.data
        │   │   ├── author.data
        │   │   ├── lorem-ipsum-child-1-1.page
        │   │   ├── lorem-ipsum-child-1-2.page
        │   │   └── lorem-ipsum-child-1-3.page
        │   ├── title.data
        │   ├── description.data
        │   ├── author.data
        │   ├── lorem-ipsum-child-1.page
        │   ├── lorem-ipsum-child-2.page
        │   └── lorem-ipsum-child-3.page
        ├── lorem-ipsum.page
        ├── dolor-sit.page
        └── no-no-no.page

Conditions 

These page conditional statements are available to quickly determine the type of page we are currently in:

  • $site->has('i') → Return true if page URL contains page offset.
  • $site->has('next') → Return true if it is possible to go to the next page.
  • $site->has('page') → Return true if there is a page to load.
  • $site->has('pages') → Return true if there are pages to load.
  • $site->has('parent') → Return true if current page has parent page.
  • $site->has('prev') → Return true if it is possible to go to the previous page.
  • $site->is('error') → Return 404 if there is no page or pages to load.
  • $site->is('home') → Return true on home page.
  • $site->is('page') → Return true on single page view.
  • $site->is('pages') → Return true on multiple page view.