0

I have created a .phtml that I added to the homepage through the adminpanel (CMS->Sites->Home->Design):

<reference name="content">
      <block type="core/template" name="sidebar"  template="sidebar/sidebar.phtml" />
</reference>

So now I wanted this .phtml to be displayed on every page of my site and I've followed this Answer: https://stackoverflow.com/questions/4449832/magento-create-a-fixed-block-in-all-pages

But it does not work, my .phtml does not get loaded. Here is my code:

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Psp_SideBar>
            <version>1.0.0</version>
        </Psp_SideBar>
    </modules>
    <global>
        <blocks>
            <psp_sidebar>
                <class>Psp_SideBar_Block</class>
            </psp_sidebar>
        </blocks>
        <helpers>
            <psp_sidebar>
                <class>Psp_SideBar_Helper</class>
            </psp_sidebar>
        </helpers>
        <models>
            <psp_sidebar>
                <class>Psp_SideBar_Model</class>
            </psp_sidebar>
        </models>
        <resources>
            <psp_sidebar_setup>
                <setup>
                    <module>Psp_SideBar</module>
                </setup>
            </psp_sidebar_setup>
        </resources>
    </global>
    <frontend>
        <layout>
            <updates>
                <psp_sidebar>
                    <file>sidebar.xml</file>
                </psp_sidebar>
            </updates>
        </layout>
    </frontend>
</config>

sidebar.xml

<?xml version="1.0"?>
<frontend>
    <layout>
        <default>
            <reference name="content">
                <block type="core/template" name="psp.sidebar" template="sidebar/sidebar.phtml" />
            </reference>
        </default>
    </layout>
</frontend>
  • change in sidebar.xml <block type="core/template" name="psp.sidebar" template="sidebar/sidebar.phtml" before="-" /> try this and let me know if works. – Aman Srivastava Apr 7 '16 at 11:50
2

You have errors in your layout update - erase frontend from last file (sidebar.xml). Also I don't think this block will appear on side as it name suggests, but I am not pretty sure what you are trying to achieve

Take a look here: http://alanstorm.com/layouts_blocks_and_templates

<layout version="0.1.0">
<default>
    <reference name="root">
        <block type="page/html" name="root" output="toHtml" template="simple_page.phtml" />
    </reference>
</default>

In your case you have to change name of reference and settings inside block comparing them with example form Alan Storm's blog.

Also after that check if you file is in good location - for custom package, theme: design/frontend/[package_name]/[theme_name]/layout

If you don't use custom one:s design/frontend/default/default/layout or if you have installed sample data: design/frontend/rwd/default(?)/layout

If you create custom extension you should separete you layout update from other layout files - for example put it inside psp/sidebar catalog inside layout folder (while doing it you have to add in config.xml in node in layout update correct name of path in case of previous change - psp/sidebar/sidebar.xml

| improve this answer | |
  • What I want to do is to add a floating button on the side of my site. In my .phtml I create the button and use javascript to move it to the side (I know thats not good practice). When I add the very first codeblock I wrote to (CMS->Sites->Home->Design) it works just like I want it to, but only for the Home page. Is there an easy to follow tutorial to create your own module that adds a .phtml to every page on your site? I looked but did not find anything that worked for me. – igor treptau Apr 7 '16 at 12:04
  • Try chaning type of block for core/tempalte - it is a proper type of block using a template (but in case you connect to your template Block with methods than change your type for psp_sidebar/[blockname] also delete output="toHtml" also at the end check your paths to phtml and layout xml according to pointed ones in layout xml and config.xml – Bartosz Kubicki Apr 7 '16 at 12:16
  • I did change the type of block to core/template and my layout.xml still does not work (it is in /design/frontend/default/MYTHEME/layout/sidebar.xml and my config.xml contains: ` <frontend>` ` <layout>` ` <updates>` ` <psp_sidebar>` ` <file>sidebar.xml</file>` ` </psp_sidebar>` ` </updates>` ` </layout>` ` </frontend>` – igor treptau Apr 7 '16 at 13:27
  • If you have it in your custom theme it won't work until you turn on your custom theme in backend - I forgot to tell you - try moving it inside `design/frontend/default/default/layout' and if it works read something about setting on custom package and theme. – Bartosz Kubicki Apr 7 '16 at 13:31
  • But I do have a custom theme enabled. Under (System->Design) it lists my design (default/MYTHEME) – igor treptau Apr 7 '16 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.