I’m a beginner and I’m trying to learn the xml markup. Sorry if this has been answered anywhere else, I have looked and I don’t think it has. I decided to imitate the demo multi-store to learn so I wanted to insert a new block over the header. I created a simple template named <i>overheader.phtml</i> in <i>template/page/html</i> folder:
<p class="demo-notice">This is a demo store. Any orders placed through this store will not be honored or fulfilled.</p>
I added a new block named <i>overheader</i> to <i>page.xml</i> like this:
The problem is: the new template isn’t displayed. I tried many values for <i>type</i> attribute but nothing changed. I read that I can use static blocks but from what I understand they contain only html code so I can’t include other templates inside of them. Moreover why layouts use xml tag if we can’t change them in this way? So what’s wrong with this code? Thank you very much
I’m also a beginner so I may not be 100% accurate in my response.
When you created a new block “overheader” in page.xml, you set its type as “page/html_overhead”. Since you want to use this type, you need to manually create this block type. These block types can be created by opening up app/code/core/Mage/. Since the top level of your block type is “page”, navigate to the “page” folder. You will see a subfolder called “Block”. This is where all the block types “page” are stored/created.
The next element of the block type is “html”, so go to the “html” folder under the “page/Block” folder. You will see a list of php files (e.g. Header.php, Footer.php, etc.). These are the php files that the other block types refer to - e.g. page/html_header, page/html_footer, etc.
Create a new file called “overhead.php”. For just a simple block, inserting the following into that file should suffice:
<?php
class Mage_Page_Block_Html_Overhead extends Mage_Core_Block_Template { function __construct() { parent::__construct(); $this->setTemplate('page/html/overheader.phtml'); }
}
?>
Then you can refer to this in your phtml file. Also, make sure that the relevant css file (skin/frontend/default/default/styles.css I believe) sets the correct dimensions for the block. Something like:
I’m a beginner and I’m trying to learn the xml markup. Sorry if this has been answered anywhere else, I have looked and I don’t think it has. I decided to imitate the demo multi-store to learn so I wanted to insert a new block over the header. I created a simple template named <i>overheader.phtml</i> in <i>template/page/html</i> folder:
<p class="demo-notice">This is a demo store. Any orders placed through this store will not be honored or fulfilled.</p>
I added a new block named <i>overheader</i> to <i>page.xml</i> like this:
The problem is: the new template isn’t displayed. I tried many values for <i>type</i> attribute but nothing changed. I read that I can use static blocks but from what I understand they contain only html code so I can’t include other templates inside of them. Moreover why layouts use xml tag if we can’t change them in this way? So what’s wrong with this code? Thank you very much
Sorry for the late hydroxide, I was on holiday Thank you very much! Your information are precious! I tried your solution and it seems to work; I have only to learn how to write code for new blocks. Thank you again! Bye
Thanks guys, another beginner here. This thread has helped me understand things a bit better.
One question though. Is adding a new file to app/code/core/Mage/html/ the correct way to approach this? I was under the impression that i should stick to modifying things under app\design\frontend\default\{myDesign} and skin\frontend\default\{myDesign} only. Easing upgrades, transfers etc.
I guess the new file in app/code/core/Mage/html/ wont be overwritten in an update… but its another thing to remember when moving or reinstalling. Is there another correct way to add a simple block?
I’ve tried this both on my active theme, and in the default core files and still can’t get the block to show up. I’ve refreshed the cache as well. Is there anything that has changed in this process since 1.3.1, or something else I may have missed?
Similarly, this is all very new to me but thought I’d post as I’m trying to do the same thing, but also worry about modifying files outside the two threads suggested in the design guide.
I’m finding I can do this by adding HTML to the head.phtml document, then track down the CSS doc to remove styling on the surrounding classes (borders/margins that sort fo thing).
head.phtml is loaded into the page whatever container phtml page is loaded, i.e. 3column.phtml, 1column.phtml etc.
I’m only inserting a <p></p> tag at present, but I hope to replace this with a <div></div> and style it using my own classes, either added to the boxes.css or inserted within a seperate custom css for my client’s needs.
Very early to say, but I believe we must be able to create your own themes without having to go into the “code” folders… just wouldn’t make sense to me with all the advice regarding “don’t as you won’t be able to upgrade”.
1) Trying to insert new DIVs, with your own styling (particularly layout) seems to conflict with pre-existing block styling.
2) Strangley, although I can manipulate background images through CSS I can’t seem to bring in my own logo. Including anything other than hardcoded logo, i.e. <img src="<?php echo $this->getLogoSrc() ?>” alt="<?php echo $this->getLogoAlt() ?>” /> just seems to get ignored.
It looks like even creating a different logo file involves manipulating “app\code\core\mage\page\etc\config.xml” so bang goes working in only the two recommended interface/theme threads (as per Dorgo’s post).
I really hope I’m just missing something simple here…
hi there i do all step but not work
my step :
i create new file Test.php in app/code/local/Mage/Page/Block/Html/
with content
<?php class Mage_Page_Block_Html_Test extends Mage_Core_Block_Template { function __construct() { parent::__construct(); $this->setTemplate('page/template/html/test.phtml'); }
} ?>
create file test.phtml in app/design/frontend/default/mytemplate_dir/template/page/html/ go to app/design/frontend/default/mytemplate_dir/layout/ and add new line before
There is a way to create the block with out extending a magento class.
First off you need to determine what type the template will be.
<block type="core/template" name="new_block_name" as="new_block_name" template="template_location"/> //here is an example pulled from catalog.xml <block type="core/template" before="cart_sidebar" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/>
Now if it is going above the header like the posts above mention you must look in magento_install_dir/app/design/frontend/default/your_theme/template/page/
I got problems with custom blocks in 1.3 as well… It worked perfectly when I added my custom block in the Mage folder, but when I tried to keep the custom blocks out of the core stuff, it didn’t work anymore.
In addition: I think this is a nice place for me to say that Magento definitely needs documentation. The fact that there are so many people asking the same question over and over again, should say enough.
<reference name="right"> <block type="core/template" name="support" as="support" template="callouts/support.phtml"/> <block type="catalog/product_compare_sidebar" before="cart_sidebar" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/> <block type="core/template" name="right.permanent.callout" template="callouts/right_col.phtml"> <action method="setImgSrc"><src>images/media/col_right_callout.jpg</src></action> <action method="setImgAlt" translate="alt" module="catalog"><alt>Keep your eyes open for our special Back to School items and save A LOT!</alt></action> </block>
1. It works however my block is showing up underneath the add to cart and compare blocks. I need the box to be first on the right hand side
2. In the code above I see a call out for the compare sidebar, however I do not see a call out for the shopping cart. How is this being called into the page???