Magento Forum

Including a static block
 
kharisma
Member
 
Total Posts:  67
Joined:  2007-10-18
Australia
 

I want to dynamically include a static block.  Reason being that the blocks are each different, yet part of a set that would be mounted in the same kind of code each time, but with some non-system variables, so it can’t be a template.

Rather than type that code out all the time, I have set the CMS pages to call a Block class to load the content for it.  The Block class extends Mage_Cms_Block_Block, which already identifies and loads blocks, so I am adapting this functionality to suit the current purpose.

However ... I am able to get the block id, and the static block is enabled (I enabled it for all stores just to be sure), but it keeps failing the test for whether $block->isActive().

I tried commenting that out for now, just to see if it would at least load the block anyway, but it still comes up empty. The function that is supposed to load the block is $block->getContent(), which doesn’t exist anywhere. I can see that there must be some clever automated way of setting and getting attributes, but that makes it hard to track down exactly where this specific function happens.

Anyway, what might the problem be?

Basically I have:

Static block: my-test-block
CMS Page: 

{{block type="module/page" block_id="my-test-block" }}
local/Mage/Module/Block/Page:
class Mage_Module_Block_Page extends Mage_Cms_Block_Block
Has a modified version of toHtml() copied from Mage_Cms_Block_Block
Is supposed to wrap the block in html code and display the page.

The page displays, but without the static block.

Any ideas as to how to proceed?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

Could you try adding the name attribute?

{{block type="module/page" block_id="my-test-block" name="some_name_here" }}
 
Magento Community Magento Community
Magento Community
Magento Community
 
kharisma
Member
 
Total Posts:  67
Joined:  2007-10-18
Australia
 

Hi Moshe

Added a name, but no change. What is the name for in this process?

(BTW, since there is also a form in this, I know that in a cms page you can put

<form action="{{store url='module/display'}}" method='POST' >
but how do you get the store url in a class method?)
 
Magento Community Magento Community
Magento Community
Magento Community
 
kharisma
Member
 
Total Posts:  67
Joined:  2007-10-18
Australia
 

OK, got the first part working - not sure what the problem was. Basically fixed it by copying the module and renaming it, then checking everything to make sure the new names were consistent. Must’ve fixed something else along the way, ‘cos it works now. Still having trouble getting the form to work, though. It goes to the right address, then says 404 Page not found.

I have got

<form action="module/form/display" method="POST">

Have also tried

$path $this->getUrl('module/form/display');
<
form action="$pathmethod="POST">

It is giving me the right address in the url, but saying Page not found.

The path to the form handler is app/code/local/Mage/Module/controllers/Form.php.
The class name is Mage_Module_FormController

What else should I be checking?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

And if you try:

<form action="{{store url='module/form/display'}}" method='POST' >
 
Magento Community Magento Community
Magento Community
Magento Community
 
kharisma
Member
 
Total Posts:  67
Joined:  2007-10-18
Australia
 

Had that in the first place and was producing an error, so tried the other ways. I thought using the curly braces was for within CMS pages?

The Block handler is outputting to the browser using toHtml() so doesn’t it need to be in a form that the browser can understand?

Just tried it again - still an error

$action "module/form/display";
$html "<form action=\"{{store url='$action'}}\" method='POST' >...";

This produces <form action="{{store url=’module/form/display’}}” method=’POST’ > on the page and &#x7B;&#x7B;store%20url=’module/form/display’&#x7D;&#x7D; in the address bar of the browser

When I use

$action "module/form/display";
<
form action='$action' method='POST' >
that produces http://domain.com/module/form/display in the browser, so at least it is the right address, but still says Page not found
 
Magento Community Magento Community
Magento Community
Magento Community
 
kharisma
Member
 
Total Posts:  67
Joined:  2007-10-18
Australia
 

Hmm. Just found Mage::getBaseUrl() in the code, so tried that - produces the right full url, but still same 404 error.

$action Mage::getBaseUrl()."module/form/display";
<
form action='$action' method='POST' >

produces http://domain.com/module/form/display and 404 error.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

Had that in the first place and was producing an error, so tried the other ways

in your first example you had {{store url=’module/display’}}

I thought using the curly braces was for within CMS pages?

I was under impression we are talking about static CMS blocks.

If you are using file templates, it should be <?=$this->getUrl('module/form/display')?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
kharisma
Member
 
Total Posts:  67
Joined:  2007-10-18
Australia
 

Hi Moshe
This is a further step in the process.  The pages I am creating have three phases

1. display instructions - from a static block into a CMS page (that’s the part I have finally got working)
2. replace that display with a questionnaire
3. display results

In order to do this, when I display the instructions, I wrap it in a form, so that hopefully it will be the same ‘page’ (same web url in browser) that gets redisplayed. Then of course the questionnaire itself is also a form, which also has to be assessed, and results displayed.

So whenever the page is rewritten, it is going directly to the browser, thus the form ‘action’ must be written accordingly. (Had tried $this->getUrl(’module/form/display’) at one point, and still wasn’t working so was looking at other options. Ended up back with $this->getUrl(’module/form/display’) though.)

The resulting action url seems to be correct, and the class that handles the resulting actions extends Mage_Core_Controller_Front_Action, so am not sure how to proceed, but will continue to look at form examples from Magento (newsletter, etc)

 
Magento Community Magento Community
Magento Community
Magento Community
 
Michae1
Enthusiast
 
Total Posts:  826
Joined:  2007-08-31
 
kharisma - 27 January 2008 02:23 AM

It is giving me the right address in the url, but saying Page not found.

The path to the form handler is app/code/local/Mage/Module/controllers/Form.php.

Is it a real file name ? Can you please rename it to FormController.php ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
kharisma
Member
 
Total Posts:  67
Joined:  2007-10-18
Australia
 

Thanks - hadn’t noticed that detail. Changed the file name but still 404.

Is there a thread somewhere that details the requirements for getting a form to work? Have got some of them, but there’s obviously some detail wrong or missing.

(BTW apologies for having this query in this forum. Had several forum windows open, then went back to the How do I forum (window already open) and started a new thread - cookies must’ve put it into whatever forum I was last viewing a thread for. )

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top