0

I have a CMS page with a URL key of "contact" (without the last 's'), I would like to add a block within it. The content of the CMS page is simply:

{{block type="core/template" name="contactForm" form_action="/contacts/index/post"template="contacts/form.phtml"}}

I know, why don't they just use Magento's default /contacts form. That's the way they have it set up but I will talk to them about changing it as it would make things easier.

Anyway the problem is I want to add a block to contactForm, I've tried with below Layout XML in a local.xml and in the CMS Page Layout Update XML section, but it doesn't work.

local.xml

<contacts_index_index>
    <reference name="contactForm">
        <block type="studioforty9_recaptcha/explicit" name="studioforty9.recaptcha.explicit" template="studioforty9/recaptcha/explicit.phtml"/>
    </reference>
</contacts_index_index>

CMS Page Layout Update XML

<reference name="contactForm">
        <block type="studioforty9_recaptcha/explicit" name="studioforty9.recaptcha.explicit" template="studioforty9/recaptcha/explicit.phtml"/>
</reference>

I'm not sure why it's not working, I also tried adding the studioforty9_recaptcha/explicit block to System > Permissions > Blocks, but that didn't work either.

I can see it is working with the /contacts form so am going to encourage them to just use this one, but am interested as to why my layout updates are not working.

I'm working on an old version of Magento, 1.7, I wonder if this may have something to do with it.

2
  • As an (irrelevant) aside, {{block type="core/template" name="contactForm" form_action="/contacts/index/post"template="contacts/form.phtml"}} should be {{block type="core/template" name="contactForm" form_action="/contacts/index/post" template="contacts/form.phtml"}}
    – tjons
    Nov 10, 2016 at 22:53
  • @jtons, nicely spotted, interestingly it was loading the block with that typo anyway
    – Holly
    Nov 10, 2016 at 23:02

1 Answer 1

1

CMS layout always loads last, and therefore will override anything that you do in local.

What I would recommend you do instead is to use REWRITE on the block class... that way the layout XML can remain the same, but your Block would be loaded instead. If you define a template in the block class it will use that value instead of what is defined in layout XML.

For the rewrite, see:

http://inchoo.net/magento/overriding-magento-blocks-models-helpers-and-controllers/

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.