问题
I want to make a newsletter subscription box on home page in content area, and for that I have made a CMS page that other code I have placed in the newsletter subscription file can call too.
I am trying to call it like this:
<?php echo $this->getLayout()->createBlock('newsletter/subscribe')->setTemplate('newsletter/subscribe.phtml')->toHtml(); ?>
but it does not show up.
Why ?
回答1:
system -> configuration -> advanced
from there enable newsletter module. and then you can use the above code to call it anywhere.
<?php echo $this->getLayout()->createBlock('newsletter/subscribe')->setTemplate('newsletter/subscribe.phtml')->toHtml(); ?>
回答2:
If you look at the newsletter.xml layout update file, you will find the subscribe block defined like this:
<reference name="left">
<block type="newsletter/subscribe" name="left.newsletter" template="newsletter/subscribe.phtml"/>
</reference>
The easiest thing you can do is add something similar to the Layout Update XML for your homepage. Simply open the homepage in the CMS Pages area of the admin, click on the Design tab, and put this in the Layout Update XML text box:
<reference name="content">
<block type="newsletter/subscribe" name="home.newsletter" template="newsletter/subscribe.phtml"/>
</reference>
You may need to play around with it to get it to show up where you want, but that should work.
来源:https://stackoverflow.com/questions/8165386/how-to-call-newsletter-subscribe-phtml-on-cms-content-home-phtml