Skip to content

Commit b2843f9

Browse files
authored
[5.0] Custom Error Pages - new feature (#40597)
1 parent 7bc53a3 commit b2843f9

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

language/en-GB/tpl_cassiopeia.sys.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ TPL_CASSIOPEIA_POSITION_BOTTOM-A="Bottom-a"
1212
TPL_CASSIOPEIA_POSITION_BOTTOM-B="Bottom-b"
1313
TPL_CASSIOPEIA_POSITION_BREADCRUMBS="Breadcrumbs"
1414
TPL_CASSIOPEIA_POSITION_DEBUG="Debug"
15+
TPL_CASSIOPEIA_POSITION_ERROR-403="Error 403"
16+
TPL_CASSIOPEIA_POSITION_ERROR-404="Error 404"
1517
TPL_CASSIOPEIA_POSITION_FOOTER="Footer"
1618
TPL_CASSIOPEIA_POSITION_MAIN-BOTTOM="Main-bottom"
1719
TPL_CASSIOPEIA_POSITION_MAIN-TOP="Main-top"

templates/cassiopeia/error.php

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@
101101

102102
// Defer font awesome
103103
$wa->getAsset('style', 'fontawesome')->setAttribute('rel', 'lazy-stylesheet');
104+
105+
// Get the error code
106+
$errorCode = $this->error->getCode();
104107
?>
105108
<!DOCTYPE html>
106109
<html lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>">
@@ -148,6 +151,11 @@
148151

149152
<div class="site-grid">
150153
<div class="grid-child container-component">
154+
<?php if ($this->countModules('error-' . $errorCode)) : ?>
155+
<div class="container">
156+
<jdoc:include type="modules" name="error-<?php echo $errorCode; ?>" style="none" />
157+
</div>
158+
<?php else : ?>
151159
<h1 class="page-header"><?php echo Text::_('JERROR_LAYOUT_PAGE_NOT_FOUND'); ?></h1>
152160
<div class="card">
153161
<div class="card-body">
@@ -167,28 +175,29 @@
167175
<blockquote>
168176
<span class="badge bg-secondary"><?php echo $this->error->getCode(); ?></span> <?php echo htmlspecialchars($this->error->getMessage(), ENT_QUOTES, 'UTF-8'); ?>
169177
</blockquote>
170-
<?php if ($this->debug) : ?>
171-
<div>
178+
</div>
179+
</div>
180+
<?php endif; ?>
181+
<?php if ($this->debug) : ?>
182+
<div>
183+
<?php echo $this->renderBacktrace(); ?>
184+
<?php // Check if there are more Exceptions and render their data as well ?>
185+
<?php if ($this->error->getPrevious()) : ?>
186+
<?php $loop = true; ?>
187+
<?php // Reference $this->_error here and in the loop as setError() assigns errors to this property and we need this for the backtrace to work correctly ?>
188+
<?php // Make the first assignment to setError() outside the loop so the loop does not skip Exceptions ?>
189+
<?php $this->setError($this->_error->getPrevious()); ?>
190+
<?php while ($loop === true) : ?>
191+
<p><strong><?php echo Text::_('JERROR_LAYOUT_PREVIOUS_ERROR'); ?></strong></p>
192+
<p><?php echo htmlspecialchars($this->_error->getMessage(), ENT_QUOTES, 'UTF-8'); ?></p>
172193
<?php echo $this->renderBacktrace(); ?>
173-
<?php // Check if there are more Exceptions and render their data as well ?>
174-
<?php if ($this->error->getPrevious()) : ?>
175-
<?php $loop = true; ?>
176-
<?php // Reference $this->_error here and in the loop as setError() assigns errors to this property and we need this for the backtrace to work correctly ?>
177-
<?php // Make the first assignment to setError() outside the loop so the loop does not skip Exceptions ?>
178-
<?php $this->setError($this->_error->getPrevious()); ?>
179-
<?php while ($loop === true) : ?>
180-
<p><strong><?php echo Text::_('JERROR_LAYOUT_PREVIOUS_ERROR'); ?></strong></p>
181-
<p><?php echo htmlspecialchars($this->_error->getMessage(), ENT_QUOTES, 'UTF-8'); ?></p>
182-
<?php echo $this->renderBacktrace(); ?>
183-
<?php $loop = $this->setError($this->_error->getPrevious()); ?>
184-
<?php endwhile; ?>
185-
<?php // Reset the main error object to the base error ?>
186-
<?php $this->setError($this->error); ?>
187-
<?php endif; ?>
188-
</div>
194+
<?php $loop = $this->setError($this->_error->getPrevious()); ?>
195+
<?php endwhile; ?>
196+
<?php // Reset the main error object to the base error ?>
197+
<?php $this->setError($this->error); ?>
189198
<?php endif; ?>
190199
</div>
191-
</div>
200+
<?php endif; ?>
192201
</div>
193202
</div>
194203
<?php if ($this->countModules('footer')) : ?>

templates/cassiopeia/templateDetails.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
<position>bottom-b</position>
4141
<position>footer</position>
4242
<position>debug</position>
43+
<!-- used directly in the error.php and included here so the position will appear in the list of available positions -->
44+
<position>error-403</position>
45+
<position>error-404</position>
4346
</positions>
4447
<languages folder="language">
4548
<language tag="en-GB">en-GB/tpl_cassiopeia.ini</language>

0 commit comments

Comments
 (0)