Mecha CMS

Add extra functionality to the core engine.

Page

Author: Taufik Nurrohman · 212 Views

Tweet

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

Table of Content

Page 

What is a page?

A page is a plain text file stored in the lot\page folder. The proper file name format for a page file is *.page where * is the page slug that only accept 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 - characters.

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

page is the default file extension to indicate that the file is a page file; a published page file. There are also some other page extensions that can be used:

  • page → published, indexed
  • archive → published, not indexed (not visible in the page list, and optionally by the search engine)
  • draft → not published, not indexed, not visible.

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 http://mecha-cms.com/lorem-ipsum.

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

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

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

Any missing header data will be replaced by the default data generated by the engine. Let’s say that the default data will be loaded at first, then they will be overridden by the real data from the page file.

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

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

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

A page file can also has connection with a folder that is located in the same directory level, by setting the folder name with the same name as the page name, without the file extension (the page state).

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

Users can store their miscellaneous data that has relationship with the page file in that folder with extension data. This is called Data.

Data 

Data has a higher priority than the page header. So, if you have a title.data stored in lot\page\lorem-ipsum folder, then the content of that file will overrides the title data that is embedded in the page header.

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

Users can also put another page files in that folder. This is called Child.

Child 

Child will overrides the item page view of current file that has relationship with the current folder —the lot\lorem-ipsum.page file— and will replace that item page view into an index page view, contain list of lot\lorem-ipsum.page’s 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 tell the extension to disable the page listing on certain folders, put the page file that has relationship with the folder inside that folder instead:

// before
lot\page\lorem-ipsum\
lot\page\lorem-ipsum.page
// after
lot\page\lorem-ipsum\lorem-ipsum.page
lot\page\

Or simply create an empty parent page duplicate. This will keep the parent page included in the post listing of the parent folder:

// before
lot\page\lorem-ipsum\
lot\page\lorem-ipsum.page
// after
lot\page\lorem-ipsum\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

Properties 

  • $site->is → Return an empty string on home page, page on item page and pages on index page. Default is 404.
  • $site->state → Return the current page state. Default is page.
  • $site->step → Return the current index page’s offset. Default is null.

Hooks 

  • elevator.page → Will affect the configuration data of the item page’s pagination.
  • elevator.pages → Will affect the configuration data of the index page’s pagination.
  • elevator.page.links → Will affect the generated links of the item page’s pagination.
  • elevator.pages.links → Will affect the generated links of the index page’s pagination.
  • elevator.page.unit → Will affect the generated HTML of the item page’s pagination.
  • elevator.pages.unit → Will affect the generated HTML of the index page’s pagination.

0 Comments

No comments yet.