Skip to content

Commit

Permalink
Prevent RuntimeException on external templates (Fix #12)
Browse files Browse the repository at this point in the history
  • Loading branch information
robbinjohansson committed Feb 7, 2018
1 parent 4755f92 commit 5354003
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion blueprints/external.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ form:
header.external_url:
type: text
label: PLUGIN_ADMIN.EXTERNAL_URL
placeholder: http://haywire.me/
placeholder: https://github.com/robbinfellow/haywire-grav
validate:
required: true

Expand Down
13 changes: 12 additions & 1 deletion haywire.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function onThemeInitialized()
}

$this->enable([
'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
'onPageInitialized' => ['onPageInitialized', 0]
]);
}

Expand All @@ -35,4 +36,14 @@ public function onTwigSiteVariables()
$this->grav['assets']->addCss($path . $assets['/css/app.css']);
}
}

public function onPageInitialized()
{
// Redirect to external_url if external page template
$template = $this->grav['page']->template();
if ($template === 'external' && isset($this->grav['page']->header()->external_url)) {
$url = $this->grav['page']->header()->external_url;
$this->grav->redirect($url);
}
}
}
20 changes: 20 additions & 0 deletions templates/external.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{#
# (RuntimeException (400) Template "external.html.twig" is not defined.)
# https://github.com/robbinfellow/haywire-grav/issues/12
# Prevent grav from throwing RuntimeException when trying to visit a page using the external template.
#}

{% extends 'partials/base.html.twig' %}

{% block content %}
<div class="container">
<div class="notification is-danger">
<strong>
{{ 'ERROR'|t }}
</strong>
<p>
This page is not available.
</p>
</div>
</div>
{% endblock %}

0 comments on commit 5354003

Please sign in to comment.