Created
September 19, 2017 07:02
-
-
Save abdusco/32ec1230684b68b602a74dc5a3b18954 to your computer and use it in GitHub Desktop.
Append/prepend multiple files to template file in ProcessWire
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace ProcessWire; | |
wire()->addHookBefore('PageRender::renderPage', function (HookEvent $e) { | |
/** @var Page $page */ | |
/** @var HookEvent $event */ | |
/** @var Template $template */ | |
$event = $e->arguments(0); | |
$options = $event->arguments(0); | |
$page = $event->object; | |
$template = $page->template; | |
if (!isset($options['prependFiles'])) $options['prependFiles'] = []; | |
if (!isset($options['appendFiles'])) $options['appendFiles'] = []; | |
// do not overwrite previous appends prepends | |
$options['prependFiles'] = array_merge($options['prependFiles'], [ | |
"{$template}.routes.php", | |
"_common.php", | |
]); | |
$options['appendFiles'] = array_merge($options['appendFiles'], [ | |
"views/{$template}.php", | |
"_after.php", | |
"_main.php", | |
]); | |
$event->setArgument(0, $options); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment