I don't know why my block isn't showing up. It's not showing up on any page, and I cleared the cache. Can someone help me figure out what I missed? However, the var_dump('test') shows up!
app/design/frontend/default/default/template/justin/head.phtml
testing this block
Justin/Bieber/Block/Sings.php
class Justin_Bieber_Block_Sings extends Mage_Core_Block_Template
{
protected function _construct()
{
parent::_construct();
var_dump("test");
}
}
config.xml
<frontend>
...
<layout>
<updates>
<bieber>
<file>justin.xml</file>
</bieber>
</updates>
</layout>
</frontend>
<global>
<blocks>
<bieber>
<class>Justin_Bieber_Block</class>
</bieber>
</blocks>
...
</global>
app/design/frontend/default/default/layout/justin.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="head">
<block type="bieber/bieber" name="justin_bieber">
<action method="setTemplate">
<template>justin/head.phtml</template>
</action>
</block>
</reference>
</default>
</layout>
In your justin.xml block type should be
<block type="bieber/sings" name="justin_bieber">
In this case "bieber" is your module alias name and "sings" is class name.
Your code seems fine to me.
Regarding justin.xml try to change it to the following:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="head">
<block type="bieber/sings" name="justin_bieber" as="justin_bieber" template="justin/head.phtml" />
</reference>
</default>
</layout>
Let me know if that works!
Symlinks were the problem. Magento won't be able to grab the file if it is in a symlinked directory.
Turn it on!
Magento/Zend not allowing symbolic links
Another thing is to turn on template hints!
Related
I have a module in app/code/community/Foo/Bar/. Now, I wrote most of it, but I have a problem adding a into head on every page. My config.xml:
<?xml version="1.0"?>
<config>
<modules>
<FooBar_BrowserSearch>
<version>0.1.0</version>
</FooBar_BrowserSearch>
</modules>
<global>
<helpers>
<browsersearch>
<class>FooBar_BrowserSearch_Helper</class>
</browsersearch>
</helpers>
</global>
<frontend>
<layout>
<updates>
<mmbrowsersearch>
<file>browsersearch.xml</file>
</mmbrowsersearch>
</updates>
</layout>
</frontend>
<default>
<bs_general>
<bs_general_settings>
<bs_shortname>My Store Search</bs_shortname>
<bs_description>My default search plugin description</bs_description>
<bs_contact>admin#mysite.com</bs_contact>
</bs_general_settings>
</bs_general>
</default>
</config>
then, I've created /app/design/frontend/base/default/layout/browsersearch.xml, like so:
<layout version="0.1.0">
<browsersearch>
<reference name="head">
<action method="addLinkRel">
<rel>search</rel>
<href>myfile.xml</href>
</action>
</reference>
</browsersearch>
</layout>
but the
I've just changed <browsersearch> into <default>, and it works.
I'm a Magento newbie, and I'm trying to separate my cart link from the other links in the navigation bar.
I did these steps:
1)Configured a new module under etc/modules
<?xml version="1.0"?>
<config>
<modules>
<Marco_TopRightLinks>
<active>true</active>
<codePool>local</codePool>
</Marco_TopRightLinks>
</modules>
</config>
2)added in app/code/local/Marco/TopRightLinks/Block
the Links.php file, with these contents:
class Marco_TopRightLinks_Block_Links extends Mage_Checkout_Block_Links
{
protected function _construct()
{
$this->setTemplate('page/template/logged-links.phtml');
}
}
3)added in app/code/local/Marco/TopRightLinks/etc
the config.xml file, with these contents:
<config>
<modules>
<Marco_TopRightLinks>
<version>0.1.0</version>
</Marco_TopRightLinks>
</modules>
<global>
<blocks>
<topright>
<class>Marco_TopRightLinks_Block</class>
</topright>
</blocks>
</global>
</config>
4)Changed page.xml from this:
<block type="page/html_header" name="header" as="header">
<block type="page/template_links" name="top.links" as="topLinks"/>
to this:
<block type="page/html_header" name="header" as="header">
<block type="page/template_links" name="top.links" as="topLinks"/>
<block type="topright/links" name="top.right_links" as="topRightLinks"/>
5) changed checkout.xml from this:
to this:
<!-- Mage_Checkout -->
<reference name="top.right_links">
<block type="topright/links" name="checkout_cart_link">
<action method="addCartLink"></action>
<!--<action method="addCheckoutLink"></action>-->
</block>
</reference>
added under [my_template]/page/template
the right-links.phtml file
This results in a Magento exception:
Invalid method Marco_TopRightLinks_Block_Links::removeLinkByUrl(Array
(
[0] => http://mysitecom/checkout/cart/
)
Can you help me in understanding what's happening and what i could do? (i don't want to touch any innter magento methods, I'm sure the addCartLink works very well as it is :D) my goal is simply to move the cart link in another place into my html
EDIT:
if, instead of extending Mage_Checkout_Block_Links
class Marco_TopRightLinks_Block_Links extends Mage_Checkout_Block_Links
I extend Mage_Page_Block_Template_Links
class Marco_TopRightLinks_Block_Links extends Mage_Page_Block_Template_Links
the exception changes in
Invalid method Marco_TopRightLinks_Block_Links::addCartLink
Try replacing topright to toprightlinks in the cinnfig .xml
<config>
<modules>
<Marco_TopRightLinks>
<version>0.1.0</version>
</Marco_TopRightLinks>
</modules>
<global>
<blocks>
<toprightlinks>
<class>Marco_TopRightLinks_Block</class>
</toprightlinks>
</blocks>
</global>
</config>
here i am giving you idea to change template from one to another with your custom block also
you can add your block via the layout system (which is how the normal content is added as well)?
Define a layout XML file for your module if you haven't already:
<frontend>
<layout>
<updates>
<your_module module="Your_Module">
<file>your/module.xml</file>
</your_module>
</updates>
</layout>
</frontend>
Use your layout file (app/design/frontend/base/default/layout/your/module.xml) to add a block to the and layout update handles. Example:
<?xml version="1.0"?>
<layout>
<a_handle_for_you>
<reference name="content">
<block type="core/text" name="yourblock">
<action method="setText">
<arg>You should see this text.</arg>
</action>
</block>
</reference>
</a_handle_for_you>
<checkout_onepage_success>
<update handle="a_handle_for_you" />
</checkout_onepage_success>
<checkout_multishipping_success>
<update handle="a_handle_for_you" />
</checkout_multishipping_success>
</layout>
you can also refer Magento Knowledge Base. to get deep idea to solve your problem
The error was that in checkout.xml I shouldn't replace the block type. Magento should use its own. I should only change the block type in page.xml, so the container is changing, while the content is remaining the same
I am trying to load a custom layout page for my custom admin page "devices". Its not working ! :)
<layout version="0.1.0">
<adminhtml_devices_index_index>
<reference name="content">
<block type="adminhtml/template" name="index" output="toHtml" template="devices/index.phtml"/>
</reference>
</adminhtml_devices_index_index>
</layout>
If this is the XML in my app/design/adminhtml/default/default/layout/devices.xml
What are the different files/attributes I must be aware of ?
Also, what does type='adminhtml/template' actually point to ?
Note: My Controller code is
public function indexAction() {
$this->loadLayout();
$this->renderLayout();
}
For a quick test, use a non-template block. The block is going to be output as a course of rendering in the "content" block, so no need to specify output="toHtml".
<reference name="content">
<block type="core/text" name="devices.test">
<action method="setText">
<val>This is some sample text</val>
</action>
</block>
</reference>
The block type argument adminhtml/template points to the block class group "adminhtml", which is defined in Mage_Adminhtml config.xml:
<global>
<blocks>
<adminhtml>
<class>Mage_Adminhtml_Block
Based on this, the adminhtml/template argument points to the block name Mage_Adminhtml_Block_Template.
Try it:
<layout version="0.1.0">
<devices_adminhtml_index_index>
<reference name="content">
<block type="adminhtml/template" name="index" output="toHtml" template="devices/index.phtml"/>
</reference>
</devices_adminhtml_index_index>
</layout>
And I not sure what here should be: adminhtml/template Try replace it with core/template
Ok so I've setup a new module to override the Contacts controller so that I can add a newsletter sign up option to it. My setup is as follows:
/app/code/local/MyNamespace/ContactsPlus/controllers/Contacts/IndexController.php:
<?php
# Controllers are not autoloaded so we will have to do it manually:
require_once 'Mage/Contacts/controllers/IndexController.php';
class MyNameSpace_ContactsPlus_Contacts_IndexController extends Mage_Contacts_IndexController
{
# Overloaded indexAction
public function indexAction() {
# Just to make sure
error_log('Yes, I did it!');
parent::indexAction();
}
}
/app/code/local/MyNamespace/ContactsPlus/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<mynamespace_ContactsPlus>
<version>0.1.0</version>
</mynamespace_ContactsPlus>
</modules>
<global>
<rewrite>
<mynamespace_contactsplus_contacts_index>
<from><![CDATA[#^/contacts/index/#]]></from>
<to>/contactsplus/contacts_index/</to>
</mynamespace_contactsplus_contacts_index>
<mynamespace_contactsplus_contacts_index>
<from><![CDATA[#^/contacts/#]]></from>
<to>/contactsplus/contacts_index/</to>
</mynamespace_contactsplus_contacts_index>
</rewrite>
</global>
<frontend>
<routers>
<mynamespace_contactsplus>
<use>standard</use>
<args>
<module>mynamespace_ContactsPlus</module>
<frontName>contactsplus</frontName>
</args>
</mynamespace_contactsplus>
</routers>
</frontend>
</config>
/app/etc/modules/MyNamespace_All.xml:
<?xml version="1.0"?>
<config>
<modules>
<MyNameSpace_ContactsPlus>
<active>true</active>
<codePool>local</codePool>
</MyNamespace_ContactsPlus>
</modules>
</config>
THe module appears in the admin modules list and it has produced the following error on my /contacts/ page:
Fatal error: Call to a member function setFormAction() on a non-object in /srv/www/foo.com/app/code/core/Mage/Contacts/controllers/IndexController.php on line 54
That's this line:
$this->getLayout()->getBlock('contactForm')->setFormAction( Mage::getUrl('*/*/post') );
I'm not sure where to go from here though, a guess is that it can't set the form action on whatever is being returned from Mage::getUrl('//post') but I'm clutching at straws tbh.
Any help of advice would be greatly appreciated!
Ok after much research, help and general frustration here is how I got it working:
First up, my module directory is set out as follows (note the caps on the directories):
/app/code/local/MyNamespace/ContactsPlus/etc/
config.xml
/app/code/local/MyNamespace/ContactsPlus/controllers/
IndexController.php
/app/code/local/MyNamespace/ContactsPlus/Helper/
Data.php
Now for the config files:
/app/code/local/MyNamespace/ContactsPlus/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<MyNameSpace_ContactsPlus>
<version>0.1.0</version>
</MyNameSpace_ContactsPlus>
</modules>
<frontend>
<routers>
<!-- Creates route to my module via /contactsplus/ - I used this for testing -->
<contactsplus>
<use>standard</use>
<args>
<module>MyNameSpace_ContactsPlus</module>
<frontName>contactsplus</frontName>
</args>
</contactsplus>
<!-- Sets Mage_Contacts route to MyNameSpace_ContactsPlus -->
<contacts>
<args>
<modules>
<MyNameSpace_ContactsPlus before="Mage_Contacts">MyNameSpace_ContactsPlus</MyNameSpace_ContactsPlus>
</modules>
</args>
</contacts>
</routers>
<!-- Sets layout config file (essential for this to work) -->
<layout>
<updates>
<contactsplus>
<file>contactsplus.xml</file>
</contactsplus>
</updates>
</layout>
</frontend>
<global>
<!-- Sets a helper class for the module, when overriding contacts this is also essential. -->
<helpers>
<contactsplus>
<class>MyNameSpace_ContactsPlus_Helper</class>
</contactsplus>
</helpers>
</global>
</config>
/app/code/local/MyNamespace/ContactsPlus/controllers/Contacts/IndexController.php:
<?php
# Controllers are not autoloaded so we will have to do it manually:
require_once 'Mage/Contacts/controllers/IndexController.php';
class MyNameSpace_ContactsPlus_IndexController extends Mage_Contacts_IndexController
{
# Overloaded indexAction
public function indexAction() {
# Just to make sure
//die('Yes, I did it!');
parent::indexAction();
}
}
/app/code/local/MyNamespace/ContactsPlus/Helper/Data.php:
<?php
class MyNameSpace_ContactsPlus_Helper_Data extends Mage_Core_Helper_Abstract
{
}
/app/etc/modules/MyNamespace_ContactsPlus.xml:
<?xml version="1.0"?>
<config>
<modules>
<MyNameSpace_ContactsPlus>
<active>true</active>
<codePool>local</codePool>
</MyNameSpace_ContactsPlus>
</modules>
</config>
/app/design/frontend/mythemepackage/mytheme/layout/contacts.xml:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="footer_links">
<!-- <action method="addLink" translate="label title" module="contacts" ifconfig="contacts/contacts/enabled"><label>Contact Us</label><url>contacts</url><title>Contact Us</title><prepare>true</prepare></action>
--></reference>
</default>
<contacts_index_index translate="label">
<!-- had to comment this out in order to prevent a duplicate form issue, if anyone has a better method for this then I'd love to here it :)
<label>Contact Us Form</label>
<reference name="head">
<action method="setTitle" translate="title" module="contacts"><title>Contact Us</title></action>
</reference>
<reference name="root">
<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
<action method="setHeaderTitle" translate="title" module="contacts"><title>Contact Us</title></action>
</reference>
<reference name="content">
<block type="core/template" name="contactForm" template="contacts/form.phtml"/>
</reference>
-->
</contacts_index_index>
<!-- added this to rewrite contacts handle to the new modules handle -->
<contacts_index_index>
<update handle="contactsplus_index_index"/>
</contacts_index_index>
</layout>
/app/design/frontend/mythemepackage/mytheme/layout/contactsplus.xml:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="footer_links">
<!-- <action method="addLink" translate="label title" module="contacts" ifconfig="contacts/contacts/enabled"><label>Contact Us</label><url>contacts</url><title>Contact Us</title><prepare>true</prepare></action>
--></reference>
</default>
<contactsplus_index_index translate="label">
<label>Contact Us Form</label>
<reference name="head">
<action method="setTitle" translate="title" module="contactsplus"><title>Contact Us</title></action>
</reference>
<reference name="root">
<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
<action method="setHeaderTitle" translate="title" module="contactsplus"><title>Contact Us</title></action>
</reference>
<reference name="content">
<block type="core/template" name="contactForm" template="contactsplus/custom_form.phtml"/>
</reference>
</contactsplus_index_index>
</layout>
I also made a copy of /app/design/frontend/mythemepackage/mytheme/template/contacts/form.phtml and placed it in /app/design/frontend/mythemepackage/mytheme/template/contactsplus/ and then modified it to suit my requirements.
Resources I found particularly useful during this process were google, IRC #magento and
http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/custom_module_with_custom_database_table
http://alanstorm.com
Hope this helps someone else at some point.
Now it's onto adding a newsletter sign up option to my new form!
In my config.xml I have:
<config>
<modules>
<Test_Quickorder>
<version>0.1.0</version>
</Test_Quickorder>
</modules>
<global>
<blocks>
<quickorder>
<rewrite>
<quickorder>Test_Quickorder_Block_Quickorder</quickorder>
</rewrite>
</quickorder>
</blocks>
</global>
<frontend>
<routers>
<quickorder>
<use>standard</use>
<args>
<module>Test_Quickorder</module>
<frontName>quickorder</frontName>
</args>
</quickorder>
</routers>
<layout>
<updates>
<quickorder>
<file>quickorder.xml</file>
</quickorder>
</updates>
</layout>
</frontend>
</config>
In app/code/community/Test/Quickorder/controllers/IndexController.php I have:
<?php
class Test_Quickorder_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout(array('default');
$this->renderLayout();
}
}
In app/design/frontend/base/default/layout/quickorder.xml I have:
<layout version="0.1.0">
<default>
<reference name="top.links">
<action method="addLink" translate="label title">
<label>Quick Order</label>
<url>quickorder</url>
<title>Quick Order</title>
<prepare/>
<urlParams/>
<position>1</position>
</action>
</reference>
</default>
<quickorder_index_index>
<reference name="root">
<action method="setTemplate">
<template>page/1column.phtml</template>
</action>
</reference>
<reference name="content">
<block type="quickorder/quickorder" name="quick" template="quickorder/quickorder.phtml"/>
</reference>
</quickorder_index_index>
</layout>
In app/design/frontend/base/default/template/quickorder/quickorder.phtml I have:
<div class="content">
<p>Hello</p>
</div>
And in app/code/community/Test/Quickorder/Block/Quickorder I have:
<?php
class Test_Quickorder_Block_Quickorder extends Mage_Core_Block_Abstract
{
}
I was expecting "Hello" to show up right in the middle of the page. Instead I get nothing. I know some part of the layout is working because when I navigate to quickorder I get
<body class="quickorder-index-index">
Can anybody point me in the right direction as to where I've gone wrong here?
Thanks in advance for any help/tips/pointers :-)
I haven't examined all your code, but this
class Test_Quickorder_Block_Quickorder extends Mage_Core_Block_Abstract
{
}
should be this
class Test_Quickorder_Block_Quickorder extends Mage_Core_Block_Template
{
}
If you want a block to render a template, it needs to be, or inherit from, Mage_Core_Block_Template.