1

Meta

  • Magento 1.9.2.1
  • Custom Template
  • Poll works fine when in sidebar
  • Poll works fine when loaded by layout xml

History

Based on this information:

http://inchoo.net/magento/magento-frontend/reusing-magento-poll-on-any-page-or-any-block/

and

https://www.demacmedia.com/magento-commerce/how-to-display-the-magento-poll-voting-form-and-results-in-a-static-block/

I'd like to show the polls module anywhere I like, using the WYSIWYG Editor.

When I add the poll on a CMS page, by adding the xml to the design tab of the new page, it all works fine. This is not available in a static CMS Block. Since I need the poll to appear in a static block, I run into a little problem.

The problem

Loading the Poll with

{{block type="poll/poll" template="poll/active.phtml" poll_id="1"}} {{block type="poll/poll" template="poll/result.phtml" poll_id="1"}}

does indeed show the poll and the results. Of course, the appear both at the same time and the results are empty.

Attempt for a solution

I tried to emulate the way the template is changed, when it's done with xml. So I created poll/anywhere.phtml like this:

<?php
    $pollId = $this->getPollId();
    $poll = $this->getLayout()->createBlock('poll/activePoll');
    $poll->setPollId($pollId);
    $poll->setPollTemplate('poll/result.phtml', 'results');
    $poll->setPollTemplate('poll/active.phtml', 'poll');
    echo $poll->toHtml();
?>

Then I load This template in the WYSIWYG Editor via:

{{block type="page/html" template="poll/anywhere.phtml" poll_id="2"}}

This leads to the same behaviour, as when I load both parts separately, only that the poll itself does not show (correct in this case), but the results are still empty.

Again, when I load it with xml, it works as expected.

For reference (from the first link), this look like this:

<reference name="content">
    <block type="poll/activePoll" name="custom.poll">
        <action method="setPollId">
            <pollId>1</pollId>
        </action>
        <action method="setPollTemplate">
            <template>poll/active.phtml</template>              
            <type>poll</type>
        </action>
        <action method="setPollTemplate">
            <template>poll/result.phtml</template>      
            <type>results</type>
        </action>
    </block>
</reference>

From What I see, the same thing should be accomplished in anywhere.phtml

The question

Is obviously, what did I do wrong, what did I miss?

Any insight is greatly appreciated.

1 Answer 1

0

Allow block in whitelist in admin-> system-> permission-> blocks-> add new block

Enter "poll/poll" in Block name and "Yes" in Is Allowed it should resolve your issue when you use poll/anywhere.phtml - template

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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