Mecha CMS

Add extra functionality to the core engine.

Page

Table of Content

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 -. And the extension recommended for page files is page.

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

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

  • page → Pages with this extension mean that they are publicly available and will appear together in the page list.
  • archive → Pages with this extension mean that they are publicly available but will not appear together in the page list.
  • draft → Pages with this extension mean they are not publicly available and will not appear together in the public page list.

If you have to translate them into numbers, then:

0: draft
1: page
2: archive

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 headers data written in a YAML syntax:

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

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

Any missing header data be replaced by default data that is generated by the engine. Let’s say that the default data will be loaded first, then it will be overwritten by the header data from the page file.

Most of the default data are just an empty string or null, which can also be evaluated to boolean false in many cases.

[
    'title' => null,
    'description' => null,
    'author' => null,
    'type' => 'HTML'
]

Note: Current file creation time will become the page time by default.

A page file can also have connections with 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 a 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 this 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. This, can then be named as Child.

Child 

Child will overwrite the page view of the current file, and will change the page view to 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 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

Condition 

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

  • $site->has('next') → Return true if it is possible to go to the next page.
  • $site->has('page') → Return 1 if there is a page to load.
  • $site->has('pages') → Return the pages count if there are pages to load.
  • $site->has('parent') → Return the parent page’s file path if current page has parent page.
  • $site->has('previous') → Return true if it is possible to go to the previous page.
  • $site->has('step') → Return true if page URL contains the page offset.
  • $site->is('$') → Return the home page’s file path on home page.
  • $site->is('error') → Return 404 if there is no page or pages to load.
  • $site->is('home') → Return the home page’s file path on home page.
  • $site->is('page') → Return the current page’s file path on item view.
  • $site->is('pages') → Return the current page’s files path on items view.
  • $site->is('search') → Return true on search results page.

0 Comments

No comments yet.