2010-12-15 2 views
1

Magentoデザインを(page.xmlを編集するのではなくlocal.xmlを使用して)編集するのが最善ですが、これはシステムはとても恐ろしく複雑ですが、これを行うことは非常に難しいことが分かります。Magentoのtop.links(topLinks)ブロックを移動できません

私が今問題にしているのは、「top.links」ブロックをヘッダー内の別のブロックに移動することができないということです。 page.xmlの現時点では、このブロックはヘッダーブロック内にあります。私は、これを動作させるためにlocal.xmlにすべてを試みましたが、私は以下の編集を試みました。

ヘッダーからtop.linksを削除し、内部の "Hud"ブロックを追加します。

<layout version="0.1.0"> 

    <default> 
     <!-- Here is where we edit the header block --> 
     <reference name="header"> 
      <remove name="top.links" /> 
      <remove name="top.search" /> 
      <!-- This is the block that holds the HUD --> 
      <block type="page/html" name="hud" as="hud" template="page/html/hud.phtml"> 
       <block type="page/template_links" name="top.links" as="topLinks" /> 
      </block> 
     </reference> 
    </default> 

</layout> 

alt text

リンク褐色ボックス内でなければならないことに注意してください(これはHUDブロックです)。

ヘッダからtop.linksブロックを除去することが、のHUDブロック

<layout version="0.1.0"> 

    <default> 
     <!-- Here is where we edit the header block --> 
     <reference name="header"> 
      <remove name="top.search" /> 
      <!-- This is the block that holds the HUD --> 
      <block type="page/html" name="hud" as="hud" template="page/html/hud.phtml"> 
       <block type="page/template_links" name="top.links" as="topLinks" /> 
      </block> 
     </reference> 
    </default> 

</layout> 

alt text

作成された新しいリンクテンプレートtop.linksのコードに基づいに添加し、この言及しませんHUDのブロックは次のようになります。

<layout version="0.1.0"> 

    <default> 
     <!-- Here is where we edit the header block --> 
     <reference name="header"> 
      <remove name="top.links" /> 
      <remove name="top.search" /> 
      <!-- This is the block that holds the HUD --> 
      <block type="page/html" name="hud" as="hud" template="page/html/hud.phtml"> 
       <block type="page/template_links" name="hud.links" as="hudLinks" template="page/template/hudLinks.phtml"/> 
      </block> 
     </reference> 
    </default> 

</layout> 

以下はこれが最も興味深い結果をもたらします

<!-- hud.phtml --> 
<div id="hud"> 
    <h3>Welcome</h3> 
    <?php echo $this->getChildHtml('hudLinks') ?> 
    <?php echo $this->getChildHtml('top.search') ?> 
</div> 

hud.phtmlです。テンプレートは見つかりましたが、何も表示されません。

alt text

私は本当にこれで無知です。私はここで何か完全に間違っているのですか?それが価値があるのは、ここでhudLinks.phtmlとtop.linksテンプレートに使用しているコードです。

<?php $_links = $this->getLinks(); ?> 
<?php if(count($_links)>0): ?> 
<ul class="links"<?php if($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif;?>> 
    <?php foreach($_links as $_link): ?> 
     <li<?php if($_link->getIsFirst()||$_link->getIsLast()): ?> class="<?php if($_link->getIsFirst()): ?>first<?php endif; ?><?php if($_link->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li> 
    <?php endforeach; ?> 
</ul> 
<?php endif; ?> 
+0

自分のテーマであれば、 'page.xml'の編集には問題はありません。 – clockworkgeek

+0

私が始めたテーマは、基本的にMagentoのベースにあるpage.xmlファイルを使用しています。私は自分のテーマのレイアウトフォルダ内でpage.xmlファイルを使用してこれを上書きしようとしましたが、うまくいかないようです。お返事をありがとうございます。 –

答えて

2

「削除」ルールは最後に処理されると思いますので、挿入するブロックの名前を変更する必要があります。 は今、リンクを追加する方法を見て:

app/design/frontend/base/default/layout/customer.xml 
51:  <reference name="top.links"> 
52-   <action method="addLink" translate="label title" module="customer"><label>My Account</label><url helper="customer/getAccountUrl"/><title>My Account</title><prepare/><urlParams/><position>10</position></action> 
53-  </reference> 

リンクをブロックという名前top.linksに追加されます。だからあなたの新しいブロックは空です。 解決方法:xmlファイルのtop.linksを検索し、見つけたコードをlocal.xmlファイルに追加します。

+0

このインスタンスを使用しているときに、他のXMLファイルとまったく同じコードをコピーして貼り付けています。私はあなたが上記で提供したコードを試し、コメントを返します。あなたの応答greg0ireに感謝します。 –

+0

@Liam Spencer:コードをコピーして貼り付けた後、新しく作成したブロックの名前と一致するように、参照タグのname属性を変更してください。 – greg0ire

+0

ありがとうございました。これは私のために働いたようで、Magentoシステムをもう少し理解する助けになるかもしれません。私は、将来私はここでより多くの質問をするだろうと確信しています!再度、感謝します! –

関連する問題