Skip to content

Instantly share code, notes, and snippets.

@abdusco
Created September 19, 2017 07:02
Show Gist options
  • Save abdusco/32ec1230684b68b602a74dc5a3b18954 to your computer and use it in GitHub Desktop.
Save abdusco/32ec1230684b68b602a74dc5a3b18954 to your computer and use it in GitHub Desktop.
Append/prepend multiple files to template file in ProcessWire
<?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