Magento如何自定义404页面?

Magento修改404页面

Magento有默认的404页面,如果想自定义一个404页面,又该如何做呢?

方法一

首先,先来看下默认的404页面:
图片描述
1.Magento的CMS部分,可以通过定义它来改变错误页面,登录后台admin->CMS->Pages:

2.打开404 Not Found页面,点击左侧的Content,就可以看到404页面的详情:
图片描述

3.现在来重新定义下404页面,比如,输入以下代码:

<div class="page-head-alt">
    <h3>D'oh! That page can't be found.</h3>
    <p><strong>Don't get angry, and don't cry.</strong> Let us
    take that burden. It's not your fault. No, really, listen to me.
    It's not your fault. We have a 24 hour hotline to deal with things
    just like this. Okay, its not really a hotline, its really
    just some encouraging words to keep trying, but hotline sounds
    so much .</p>
    <p>Sorry but the page you are looking for cannot be found.
    If you're in denial and think this is a conspiracy that cannot
    possibly be true,</p>
</div>
<dl> 
    <dt>Perhaps you are here because:</dt>
    <dd>
        <ul class="disc">
            <li>The page has moved</li>
            <li>The page is no longer exists</li>
            <li>You were looking for your puppy and got lost</li>
            <li>You like 404 pages</li>
        </ul>
    </dd>
    </dl>
<dl>
    <dt>What can you do?</dt> 
    <dd>Have no fear, help is near! There are many ways you can get back on track with Magento Demo Store.</dd> 
    <dd>
        <ul class="disc">
            <li><a onclick="history.go(-1);" href="#">Go back</a> to the
            previous page.</li>
            CMS and Design
            30
            <li>Use the search bar at the top of the page to search for
            your products.</li>
            <li>Follow these links to get you back on track!<br /><a
            href="/">Store Home</a><br /><a href="/customer/account/">My
            Account</a></li>
        </ul>
    </dd>
</dl>

4.点击save page,重新打开,可以看到404页面已经发生变化。
图片描述

方法二

方法一,是通过在后台配置修改,除此之外,还需要知道的是,修改404页面,也可以通过修改模板来更改。

1.首先要将CMS中的404 Not Found 的状态改成disable

2.找到 no-route.phtml页面,路径为app/design/frontend/base/default/
template/cms/default/no-route.phtml,打开,会看到如下代码:

There was no 404 CMS page configured or found.

3.再次打开前台页面,查看是否与上述代码内容一致,前台页面为:
图片描述

4.由此,可以通过修改模板文件来修改404页面。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Magento 2中发送多个附件的电子邮件,您需要对`Magento\Framework\Mail\Template\TransportBuilder`类进行扩展。 下面是一个示例代码,它可以让您在Magento 2中发送多个附件的电子邮件: 1. 创建 `Vendor\Module\Model\Mail\Template\TransportBuilder.php` 文件并添加以下代码: ```php <?php namespace Vendor\Module\Model\Mail\Template; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Exception\MailException; use Magento\Framework\Mail\Template\TransportBuilder as MagentoTransportBuilder; use Magento\Framework\Mail\TransportInterfaceFactory; use Magento\Framework\Translate\Inline\StateInterface; use Magento\Store\Model\StoreManagerInterface; class TransportBuilder extends MagentoTransportBuilder { /** * @var array */ protected $attachments = []; /** * @param array $attachments * @return $this */ public function addMultipleAttachment($attachments = []) { foreach ($attachments as $attachment) { if (file_exists($attachment['path'])) { $this->attachments[] = [ 'type' => $attachment['type'], 'name' => $attachment['name'], 'path' => $attachment['path'] ]; } } return $this; } /** * @param null|string|array $to * @param array $templateVars * @param null|string $templateOptions * @param null|string $transportOptions * * @throws MailException * * @return TransportInterfaceFactory */ public function getTransport( $to = null, array $templateVars = [], $templateOptions = null, $transportOptions = null ) { if (!empty($this->attachments)) { foreach ($this->attachments as $attachment) { $this->message->createAttachment( file_get_contents($attachment['path']), $attachment['type'], \Zend_Mime::DISPOSITION_ATTACHMENT, \Zend_Mime::ENCODING_BASE64, $attachment['name'] ); } } return parent::getTransport($to, $templateVars, $templateOptions, $transportOptions); } } ``` 2. 创建 `Vendor_Module` 模块的 `di.xml` 文件并添加以下代码: ```xml <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Framework\Mail\Template\TransportBuilder" type="Vendor\Module\Model\Mail\Template\TransportBuilder" /> </config> ``` 3. 在您的模块中使用以下代码发送多个附件的电子邮件: ```php <?php namespace Vendor\Module\Controller\Index; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Framework\Mail\Template\TransportBuilder; use Magento\Framework\Translate\Inline\StateInterface; use Magento\Store\Model\StoreManagerInterface; class SendEmail extends Action { /** * @var TransportBuilder */ protected $transportBuilder; /** * @var StateInterface */ protected $inlineTranslation; /** * @var StoreManagerInterface */ protected $storeManager; /** * @param Context $context * @param TransportBuilder $transportBuilder * @param StateInterface $inlineTranslation * @param StoreManagerInterface $storeManager */ public function __construct( Context $context, TransportBuilder $transportBuilder, StateInterface $inlineTranslation, StoreManagerInterface $storeManager ) { $this->transportBuilder = $transportBuilder; $this->inlineTranslation = $inlineTranslation; $this->storeManager = $storeManager; parent::__construct($context); } /** * @return void */ public function execute() { $attachmentOne = [ 'name' => 'Attachment One', 'path' => 'path/to/attachment/one.pdf', 'type' => 'application/pdf' ]; $attachmentTwo = [ 'name' => 'Attachment Two', 'path' => 'path/to/attachment/two.pdf', 'type' => 'application/pdf' ]; try { $this->inlineTranslation->suspend(); $this->transportBuilder->setTemplateIdentifier('your_email_template_id') ->setTemplateOptions([ 'area' => 'frontend', 'store' => $this->storeManager->getStore()->getId() ]) ->setTemplateVars([]) ->setFrom([ 'email' => 'sender@example.com', 'name' => 'Sender Name' ]) ->addTo('recipient@example.com', 'Recipient Name') ->addMultipleAttachment([$attachmentOne, $attachmentTwo]) ->getTransport() ->sendMessage(); $this->inlineTranslation->resume(); $this->messageManager->addSuccess(__('Your email was sent successfully.')); } catch (\Exception $e) { $this->inlineTranslation->resume(); $this->messageManager->addError(__('There was an error sending your email. Please try again later.')); } return $this->_redirect('*/*/index'); } } ``` 以上代码将会发送带有两个附件的电子邮件。您可以根据自己的需要更改附件的数量和详细信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值