Mecha CMS

Mecha CMS blog and documentation.

Class Shield

Updated: Sunday, 07 August 2016

Page rendering.

The Shield class will first check whether the given file name is exists in the current active shield folder. If it does exist, then the generated file path will be relative to the current shield folder. If it doesn’t, then it will check whether the given file name is exists in the chunks folder. If it does exist, then the generated file path will be relative to the chunks folder. Otherwise, the generated file path will be relative to ROOT.

Render a Shield

The example below will load article.php file to the page:

Shield::attach('article');

Filters that will affect the loaded shield:

FilterDescription
shield:pathWill affect the generated shield path.
shield:lotWill affect the generated lot data.
shield:inputWill affect the shield input when output buffer is enabled.
shield:outputWill affect the shield output when output buffer is enabled.

Weapons that will affect the loaded shield:

HookDescription
shield_lot_beforeWill be triggered before lot data extraction.
shield_lot_afterWill be triggered after lot data extraction.
shield_beforeWill be triggered before shield output.
shield_afterWill be triggered after shield output.

Render a 404 Page

Shield::abort();

Optional with custom 404 file:

Shield::abort('404-custom');

Shield Variable

Set Variable

Let’s say you have a shield file named as custom.php contains variables like this:

<article class="post">
  <h3 class="post-title"><?php $title ?></h3>
  <div class="post-body"><?php echo $content; ?></div>
</article>

To make $title and $content becomes available in the shield, you need to define them before attaching the shield:

Shield::lot(array(
    'title' => 'Test Title',
    'content' => '<p>Test content.</p>'
))->attach('custom');

Get Variable

$content = Shield::lot('content');

Shield Chunk

Include shield part to the shield being attached:

<?php Shield::chunk('header'); ?>

Filters that will affect the loaded shield:

FilterDescription
chunk:pathWill affect the generated chunk path.
chunk:lotWill affect the generated lot data.
chunk:inputWill affect the chunk input when output buffer is enabled.
chunk:outputWill affect the chunk output when output buffer is enabled.

Weapons that will affect the loaded shield:

HookDescription
chunk_lot_beforeWill be triggered before lot data extraction.
chunk_lot_afterWill be triggered after lot data extraction.
chunk_beforeWill be triggered before chunk output.
chunk_afterWill be triggered after chunk output.

Shield Info

var_dump(Shield::info('normal'));

Check if Shield Already Exists

if($path = Shield::exist('normal')) { … }
Donation and Email Subscription