Mecha CMS


Page Property

Using page properties.

To call a property from a page, do this:


The default value is always null. This is the thing that makes Mecha version 2.x.x different from version 1.x.x. In version 1.x.x, calling a property that does not exist from a page will trigger an error message, but not in version 2.x.x. In version 2.x.x, any page property is valid and has the value of null unless you set a value explicitly to it, either from page header, page data, or from a return value that is generated by hooks.

To set a value to the foo_bar property, add a data in the page header with foo_bar as the property key:

title: Test Page
description: Testing page property.
type: Markdown
foo_bar: Test property value of `foo_bar`.

Lorem ipsum dolor sit amet.

To set a value to the foo_bar property from a separated file, add a file named as to the related folder:

└── page\
    ├── test-page\
    │   └──

To set a value to the foo_bar property with a hook, do this:

Hook::set('page.foo_bar', function($value) {
    // `$value` is `null` by default
    return 'Test property value of `foo_bar`.';

Now, $page->foo_bar will return “Test property value of `foo_bar`.”