Skip to content

Commit 6fcabcb

Browse files
Custom Layout as Hook
So that other extension(s) can remove it easily.
1 parent a32773b commit 6fcabcb

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ Layout Extension for [Mecha](https://github.com/mecha-cms/mecha)
88
Release Notes
99
-------------
1010

11-
### 2.0.0
11+
### 2.0.1
1212

1313
- Moved from [./mecha-cms/mecha](https://github.com/mecha-cms/mecha).

about.page

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Common automation features to speed up the site creation process.
44
icon: 'M13,3V9H21V3M13,21H21V11H13M3,21H11V15H3M3,13H11V3H3V13Z'
55
author: Taufik Nurrohman
66
type: Markdown
7-
version: 2.0.0
7+
version: 2.0.1
88
...
99

1010
### Features

index.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,10 @@ function get() {
5959
}
6060
}
6161
}
62-
function route($content, $path) {
63-
\ob_start();
64-
\ob_start("\\ob_gzhandler");
62+
function page($content) {
6563
if (\is_array($content) && \class_exists("\\Page")) {
6664
$page = $GLOBALS['page'] ?? new \Page;
67-
if ($page && $page instanceof \Page && ($layout = $page->layout)) {
65+
if ($page && $page instanceof \Page && $page->exist() && ($layout = $page->layout)) {
6866
// `$content = ['.\lot\y\log\page\gallery.php', [], 200];`
6967
if (0 === \strpos($layout, ".\\")) {
7068
$layout = \stream_resolve_include_path(\PATH . \D . \strtr(\substr($layout, 2), ["\\" => \D]));
@@ -73,6 +71,11 @@ function route($content, $path) {
7371
$content[0] = $layout;
7472
}
7573
}
74+
return $content;
75+
}
76+
function route($content, $path) {
77+
\ob_start();
78+
\ob_start("\\ob_gzhandler");
7679
// `$content = ['page', [], 200];`
7780
if (\is_array($content) && isset($content[0]) && \is_string($content[0])) {
7881
if ($r = \Layout::get(...$content)) {
@@ -90,6 +93,7 @@ function route($content, $path) {
9093
}
9194
\Hook::set('content', __NAMESPACE__ . "\\content", 20);
9295
\Hook::set('get', __NAMESPACE__ . "\\get", 0);
96+
\Hook::set('route', __NAMESPACE__ . "\\page", 900);
9397
\Hook::set('route', __NAMESPACE__ . "\\route", 1000);
9498
}
9599

0 commit comments

Comments
 (0)