Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 2
How do I call a static block inside top.phtml
 
gw468
Jr. Member
 
Avatar
Total Posts:  22
Joined:  2007-12-16
 

I’ve searched the forum and lots of posts cover replacing the category menu with the footer navigation and things similar to that, but those posts don’t seem to answer my question.

First off, if you can tell me how to link to an external site via a category in the back end, then skip the rest of this post and just give me that solution. If not, read on…

How do I call a static block inside the file top.phtml? I’m trying to add links to the left and/or right of the default category navigation that can link to external sites. I want to create a static block called top_left_links and one called top_right_links, then use them for code to complete my top navigation, such as:

<li onmouseover="toggleMenu(this,1)" onmouseout="toggleMenu(this,0)" class="level0 parent"><a href="myOtherSites"><span>My Other Sites</span></a>
  <
ul class="level0">
    <
li class="level1"><a href="http://externalSite1"><span>External Site One</span></a></li>
    <
li class="level1 last"><a href="http://externalSite2"><span>External Site Two</span></a></li>
  </
ul>
</
li>
In the front end, this would add a link beside my category navigation that says “My Other Sites”, when moused over, it would drop down to reveal the two sites. It would look and act exactly the same as the rest of the dynamically created category links.

Here’s an example of where I want to call the static blocks:

<div class="header-nav-container">
    <
div class="header-nav">
        <
h4 class="no-display"><?php echo $this->__('Category Navigation:'?></h4>
        <
ul id="nav">

<!-- ********** 
insert code to call top_left_links static block here ********** -->

        
<?php foreach ($this->getStoreCategories() as $_category): ?>
            <?php 
echo $this->drawItem($_category?>
        <?php 
endforeach ?>

<!-- ********** insert code to call top_right_links static block here ********** -->

        </
ul>
    </
div>
</
div>

Any help would be GREATLY appreciated.
gw

 
Magento Community Magento Community
Magento Community
Magento Community
 
Unirgy
Guru
 
Avatar
Total Posts:  478
Joined:  2007-09-07
 

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('top_left_links')->toHtml() ?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
gw468
Jr. Member
 
Avatar
Total Posts:  22
Joined:  2007-12-16
 

Thanks Saharian. That did the trick. Perfect for what I wanted. grin

 
Magento Community Magento Community
Magento Community
Magento Community
 
Web Man Walking
Jr. Member
 
Total Posts:  18
Joined:  2008-07-23
 

Hey

Just wanted to say that this worked for me as well, thanks for the nice answer.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jacob.R
Member
 
Avatar
Total Posts:  32
Joined:  2008-10-30
London
 
gw468 - 19 July 2008 01:23 PM

First off, if you can tell me how to link to an external site via a category in the back end, then skip the rest of this post and just give me that solution. If not, read on…

How do I call a static block inside the file top.phtml? I’m trying to add links to the left and/or right of the default category navigation that can link to external sites. I want to create a static block called top_left_links and one called top_right_links, then use them for code to complete my top navigation, such as:

<li onmouseover="toggleMenu(this,1)" onmouseout="toggleMenu(this,0)" class="level0 parent"><a href="myOtherSites"><span>My Other Sites</span></a>
  <
ul class="level0">
    <
li class="level1"><a href="http://externalSite1"><span>External Site One</span></a></li>
    <
li class="level1 last"><a href="http://externalSite2"><span>External Site Two</span></a></li>
  </
ul>
</
li>
In the front end, this would add a link beside my category navigation that says “My Other Sites”, when moused over, it would drop down to reveal the two sites. It would look and act exactly the same as the rest of the dynamically created category links.

Here’s an example of where I want to call the static blocks:
<div class="header-nav-container">
    <
div class="header-nav">
        <
h4 class="no-display"><?php echo $this->__('Category Navigation:'?></h4>
        <
ul id="nav">

<!-- ********** 
insert code to call top_left_links static block here ********** -->

        
<?php foreach ($this->getStoreCategories() as $_category): ?>
            <?php 
echo $this->drawItem($_category?>
        <?php 
endforeach ?>

<!-- ********** insert code to call top_right_links static block here ********** -->

        </
ul>
    </
div>
</
div>

Has anyone found out if this can be done in admin?

I am trying to follow the steps above so I can add a link to my home page in the catalog default header nav bar. E.g. I have Magento shop as link on my website: http://www.mysite.co.uk/magento I want the new link to take people back to http://www.mysite.co.uk.

I am not sure where to add the first bit of code ‘<li></li>’ . Please provide some guidance.

Jacob

 
Magento Community Magento Community
Magento Community
Magento Community
 
oscar_09
Jr. Member
 
Total Posts:  9
Joined:  2009-01-26
 

Can this be modified to add two top level menu items, each of them calling from a separate block?

Duplicating this code and calling a separate block only creates one extra menu, and the second block is called as a submenu under this. I can’t make it be it’s own top level menu. Have tried putting in a </ul> and new <ul> tag and adding the top menu css class but this still doesn’t make it a separate top level menu.

Any help MUCH appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
manojninave
Jr. Member
 
Avatar
Total Posts:  10
Joined:  2009-09-06
Nagpur
 

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('jewelery-block')->toHtml() ?>

Here ‘jewelery-block ‘ is Identifier when you created new static block.

you can show static block any where u want.
wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
ferozmansuri
Jr. Member
 
Total Posts:  22
Joined:  2011-10-05
 

Thnx Unirgy for the solution..

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tusher Khan
Member
 
Total Posts:  66
Joined:  2011-01-07
 

Here is a great way to create & show static block in magento frontend:

http://www.xpressbangla.com/creating-and-showing-a-static-block-in-magento-frontend/

 
Magento Community Magento Community
Magento Community
Magento Community
 
MageTitan
Member
 
Avatar
Total Posts:  58
Joined:  2009-10-16
Salt Lake City, Utah USA
 

Getting the layout and adding a block in template file works, but I’d like to offer another solution.
I would add a block using the local.xml layout file, then call that block from the header.html template. This is a little more efficient, and will be cached better.

Open (or create) your local.xml layout file. If you are looking at adding this to EVERY page, add (or create) the block in the <default> section.

<default>
  <
reference name="header">
    <
block type="cms/block" name="topLeftLinks" as="topLeftLinks">
      <
action method="setBlockId"><block_id>top_left_links</block_id></action>
    </
block>
  </
reference>
</default>

Just be sure the identifier for your static block is top_left_links.

Now, call your created block from the .phtml template file

<?php echo $this->getChildHtml('topLeftLinks'); ?>

With this setup, the block should cache, instead of having to parse each load.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Fixfinn
Jr. Member
 
Total Posts:  25
Joined:  2011-07-07
 

And what do you do if You want the static block in just one category?

in advance thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
MageTitan
Member
 
Avatar
Total Posts:  58
Joined:  2009-10-16
Salt Lake City, Utah USA
 

Not a problem! Categories have a section to add XML layout changes as well. Go to Catalog->Manage Categories, then select your category, and click on the tab Custom Design. There is a text area there labeled Custom Layout Update. Paste the XML changes in that section. You’ll still need to add the change to your phtml template where you want the block to show up.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Fixfinn
Jr. Member
 
Total Posts:  25
Joined:  2011-07-07
 

Thanks! That worked!

Now I just have to find out how to put a product price in the static block, so it will update itself, when ever the price is changing.

/Finn

 
Magento Community Magento Community
Magento Community
Magento Community
 
Fixfinn
Jr. Member
 
Total Posts:  25
Joined:  2011-07-07
 

Hmm!?

Now I got this fucked up again!

I want a different static block in top of my product list in each category I have.
I know I can use “Description” in category, but that does not show up exactly where I want it to be.

So this is want I do:

I choose a category
I put this in “Custom Design"-tab under special layout.

“ <reference name="category-products">
<block type="cms/block" name="staticblockLinks" as="staticblockLinks">
<action method="setBlockId"><block_id>logotext</block_id></action>
</block>
</reference>

Site-layout I set to what I want

in the file, list.phmtl, I type this

<div class="category-products">
<?php /* echo $this->getToolbarHtml() */ ?>
<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>

<!-- <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('rosettext')->toHtml() ?><!-- Show static block -->

<?php echo $this->getChildHtml('staticblocklinks'); ?>

<?php $_iterator = 0; ?>
<ol class="products-list" id="products-list">

the red line is active, as You can see, but it does not show anything.
My staticblock id is logotext.

What do i do wrong?

if I instead use the line in blue, it works, but it is the same staticblocks for all category, I need a specific for each, so I have to find which category is showing?

for any help , thanks

/finn

 
Magento Community Magento Community
Magento Community
Magento Community
 
MageTitan
Member
 
Avatar
Total Posts:  58
Joined:  2009-10-16
Salt Lake City, Utah USA
 

You have to be very careful about capitalization and how other blocks are called. The code is ALMOST right.

<reference name="category-products">

Needs to be:

<reference name="category.products">

You can see this in the catalog.xml layout file.

Then, according to your own XML update, you need to set your phtml code to be (notice the caps):

<?php echo $this->getChildHtml('staticblockLinks'); ?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Fixfinn
Jr. Member
 
Total Posts:  25
Joined:  2011-07-07
 

Hi

Thank You for Your reply.

Unfortenally, it does not work.

Any other idea?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2