2012-09-27 18 views
1

我想更改magento中的消息位置(成功/錯誤)。我得到了這個代碼。消息(成功/錯誤)在magento中的路徑?

這一個是佈局:

<layout> 
    <default> 
     <reference name="after_body_start"> 
      <block type="core/template" name="top.messages" template="core/messages/top.phtml" before="-" /> 
     </reference> 
    </default> 
</layout> 

這一個模板文件:

<?php $_messageCollection = $this->getMessagesBlock()->getMessageCollection() ?> 

<?php if ($_messageCollection->count()): ?> 
<div> 
<?php 
    echo $this->getMessagesBlock()->getGroupedHtml(); 
    $_messageCollection->clear(); 
?> 
</div> 
<?php endif; ?> 

這是用於更改錯誤/成功消息頁面頂部的代碼之一。

我需要更改消息的設計。哪個文件包含messages.phtml?我用這個路徑文件app/design/frontend/your_package/your_theme/template/core/

但它不工作。任何人都可以幫助改變這個設計。

感謝

回答

5

不是在模板文件生成的HTML,但在代替塊 - Mage_Core_Block_Messages

因此,如果你想定製這一則:

  1. 重寫Mage_Core_Block_Messages,所以你可以提供自己的getGroupedHtml()
  2. 版本自定義模板,以便它使用getMessages(),而不是getGroupedHtml()

如果你打算使用方法2,那麼你可以看看core/messages.phtml的靈感。您的模板可能看起來類似於:

<?php 

$types = array(
    Mage_Core_Model_Message::ERROR, 
    Mage_Core_Model_Message::WARNING, 
    Mage_Core_Model_Message::NOTICE, 
    Mage_Core_Model_Message::SUCCESS 
); 

$html = ''; 
foreach ($types as $type) { 
    if ($messages = $this->getMessagesBlock()->getMessages($type)) { 
     if (!$html) { 
      $html .= '<ul class="messages">'; 
     } 
     $html .= '<li class="' . $type . '-msg">'; 
     $html .= '<ul>'; 

     foreach ($messages as $message) { 
      $html.= '<li>'; 
      $html.= $message->getText(); 
      $html.= '</li>'; 
     } 
     $html .= '</ul>'; 
     $html .= '</li>'; 
    } 
} 
if ($html) { 
    $html .= '</ul>'; 
} 
echo $html; 
?> 
<?php $_messageCollection = $this->getMessagesBlock()->getMessageCollection()->clear() ?> 

不是一個模板的最好的代碼,因此你將要考慮重新分解和移動出一些邏輯來塊,這將涉及創建自己的模塊。

-1

Prasoft的我明白了什麼 首先,你需要改變位置和錯誤消息的設計。

一要更改設計:您可以編輯CSS來做到這一點,但如果你也想改變HTML結構,那麼請參閱文件

的Magento /應用程序/設計/前端/基/默認/模板/core/messages.phtml

當然,你需要做你的主題的變化。

二,要更改消息的位置,您需要引用該文件。

的Magento /應用程序/設計/前端/基/默認/模板/頁/ 1column.phtml

參考代碼。

<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>> 
<?php echo $this->getChildHtml('after_body_start') ?> 
<div class="wrapper"> 
    <?php echo $this->getChildHtml('global_notices') ?> 
    <div class="page"> 
    <?php echo $this->getChildHtml('header') ?> 
    <div class="main-container col1-layout"> 
     <div class="main"> 
      <?php echo $this->getChildHtml('breadcrumbs') ?> 
      <div class="col-main"> 
       <?php echo $this->getChildHtml('global_messages') ?> 
       <?php echo $this->getChildHtml('content') ?> 
      </div> 
     </div> 
    </div> 
    <?php echo $this->getChildHtml('footer') ?> 
    <?php echo $this->getChildHtml('before_body_end') ?> 
</div> 
</div> 
<?php echo $this->getAbsoluteFooter() ?> 
</body> 

正如你所談論的永遠是下段global_messages因此改變,根據你的HTML結構中的位置重新定位此<?php echo $this->getChildHtml('global_messages') ?>行的錯誤消息。