Skip to content

Commit

Permalink
add custom error page
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDev committed Dec 23, 2022
1 parent fa4d9cf commit 055f3d4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
18 changes: 8 additions & 10 deletions packages/core/src/templates/TwigBundle/Exception/error.html.twig
@@ -1,11 +1,9 @@
{% extends view('/base.html.twig') %}
{% set error_page = p('404') %}

{% block title %}{{ 'error.title'|trans }}{% endblock %}

{% block body %}
<div class="container mx-auto mt-5">
<h1>{{ 'error.title'|trans|raw }}</h1>
<p>{{ (status_code is defined ? 'error.serverSay'|trans ~ ' <em>' ~ status_code ~ '</em> <em>' ~ status_text ~ '</em>' : null)|raw }}</p>
<p>{{ 'error.description'|trans|raw }}</p>
</div>
{% endblock %}
{% if error_page is not null %}
{{ render(controller(
'Pushword\\Core\\Controller\\PageController::showPage', {page: error_page}
)) }}
{% else %}
{% include '/error.html.twig'|view %}
{% endif %}
11 changes: 11 additions & 0 deletions packages/core/src/templates/error.html.twig
@@ -0,0 +1,11 @@
{% extends view('/base.html.twig') %}

{% block title %}{{ 'error.title'|trans }}{% endblock %}

{% block body %}
<div class="container mx-auto mt-5">
<h1>{{ 'error.title'|trans|raw }}</h1>
<p>{{ (status_code is defined ? 'error.serverSay'|trans ~ ' <em>' ~ status_code ~ '</em> <em>' ~ status_text ~ '</em>' : null)|raw }}</p>
<p>{{ 'error.description'|trans|raw }}</p>
</div>
{% endblock %}
Binary file modified packages/skeleton/var/app.db
Binary file not shown.
Expand Up @@ -35,7 +35,13 @@ protected function generateErrorPage(?string $locale = null, string $uri = '404.
$this->requestStack->push($request);
}

$filepath = $this->getStaticDir().(null !== $locale ? '/'.$locale : '').'/'.$uri;

if (file_exists($filepath)) {
return;
}

$dump = $this->parser->compress($this->twig->render('@Twig/Exception/error.html.twig'));
$this->filesystem->dumpFile($this->getStaticDir().(null !== $locale ? '/'.$locale : '').'/'.$uri, $dump);
$this->filesystem->dumpFile($filepath, $dump);
}
}

0 comments on commit 055f3d4

Please sign in to comment.