跳至主要内容
版本:5.1

自定义错误页面

从 Joomla 5.0 开始,默认的 Cassiopeia 模板现在可以自定义以支持自定义 404 和 403 页面。

现在可以使用两个新的模块位置(error-403 和 error-404),它们将内容添加到模板的 error.php 文件中,以替换默认消息,具体取决于它是 403(禁止)还是 404(未找到)错误。

如果不存在模块,则显示现有的错误页面文本;如果启用了调试,则调试信息仍显示在模块下方。

默认 404 错误页面

Screenshot of the standard 404 error page

自定义 404 错误页面示例

Screenshot of custom 404 error page with images and buttons

Screenshot of funny custom 404 error page

向模板添加自定义错误页面

可以通过使用以下代码获取错误代码,然后在该模块位置显示任何模块,将此功能添加到您自己的模板 error.php 文件中。

<?php $errorCode = $this->error->getCode(); ?>
<?php if ($this->countModules('error-' . $errorCode)) : ?>
<div class="container">
<jdoc:include type="modules" name="error-<?php echo $errorCode; ?>" style="none" />
</div>
<?php else : ?>

这是所需的最小代码,但您可能需要进一步自定义它。