Plugin: Poll Position Template Tags


Briefly, CompletePoll is the only tag available in Poll Position. This tag will create a poll form and results for you, along with a number of class names so you can style the form and results as necessary.

In addition to CompletePoll, a comprehensive set of tags is available in Poll Position: Champion; all listed below. If you’re using Poll Position: Champion you will find polls.mtml in the plugins/PollPosition/default_templates/ folder, which provides a form using these tags—it may serve as a good starting point for you.

All of Poll Position’s tags support static publishing only; dynamic publishing is not supported.

CompletePoll

Outputs a form with all the necessary HTML for a poll. If Javascript elements have been properly included on the page, this single tag generates a fully-functional poll. The most recently-created poll with voting open will be published.

Attributes

  • poll_id, as in <mt:CompletePoll poll_id="123">. Returns complete HTML for the specified poll. Any poll can be specified, including those with voting closed, or that are unpublished. A poll’s ID can be found on the Edit Poll page.

Sample Form

What follows is a sample form generated by the CompletePoll tag. Class names have been highlighted, which you can use to style the poll on your site.

<div class="poll-container" id="poll-1">
    <div class="poll-question">
        <p>What is your favorite color?</p>
    </div>
    <form id="poll-form-1" class="poll-form" name="poll-form-1" method="post" action="" onsubmit="return submitVote(1);">
        <input type="hidden" name="__mode" value="save_poll_choice" />
        <input type="hidden" name="poll_id" value="1" />
        <input type="hidden" name="blog_id" value="1" />
        <input type="hidden" name="type" id="type_1" value="poll" />
        <input type="hidden" name="results_only" value="0" />
        <div class="poll-choices">
            <div class="poll-choice">
                <input type="radio" class="poll-choice-option" id="poll-1-choice-0" name="poll_choice" value="0" /> <label for="poll-1-choice-0">Red</label>
            </div>
            <div class="poll-choice">
                <input type="radio" class="poll-choice-option" id="poll-1-choice-1" name="poll_choice" value="1" /> <label for="poll-1-choice-1">Green</label>
            </div>
        </div>
        <input type="submit" class="poll-submit" id="poll-submit-1" value="Submit" />
        <p class="view-results-link"><a href="javascript:viewResults(1);">View results</a></p>
    </form>
    <div class="poll-results" id="poll-results-1"></div>
    <script type="text/javascript">
        checkVote(1);
    </script>
</div>

Polls

A block tag to enter the polls context. Available in Poll Position: Champion only.

Attributes

  • poll_id, as above.
  • lastn, just as it’s used within the rest of MT, to display the last “N” polls.
  • offset, just as it’s used within the rest of MT, in conjuction with lastn.

PollID

Returns the id of the current poll. This is a particularly important value because it’s integral to creating a unique form. Must be used in the Polls context. Available in Poll Position: Champion only.

PollTitle

Returns the title you’ve entered for your poll. Must be used in the Polls context. Available in Poll Position: Champion only.

PollQuestion

Returns the question for your poll. Must be used in the Polls context. Available in Poll Position: Champion only.

PollTotalVotes

Returns the total number of votes received for a poll, aggregating all response counts. Must be used in the Polls context. Available in Poll Position: Champion only.

PollChoices

A block tag to enter the choice context. Note that you must enter the poll context (with <mt:Polls> ... </mt:Polls>) in order to use this tag. Available in Poll Position: Champion only.

PollChoiceID

Returns the id of the current choice. As with PollID this tag is important because it helps create a unique form. Must be used in the PollChoices context. Available in Poll Position: Champion only.

PollChoiceText

Returns the text label of the current choice. Must be used in the PollChoices context. Available in Poll Position: Champion only.

PollChoiceVotes

Returns a count of the total number of votes received by the choice. Must be used in the PollChoices context. Available in Poll Position: Champion only.

IfPollIncluded

This tag is used in conjunction with a Poll Position Custom Field to publish a poll in the following contexts: Entry, Page, Category, Folder and Author. Available in Poll Position: Champion only.

After creating an Entry Custom Field of the “Poll” type, an author will be able to select from existing polls to publish with that entry. (Of course, that’s true for any Custom Field Object you create.) The IfPollIncluded tag is integral to making that work. In the following example, <mt:entrydata_poll_position> is the custom Field template tag name.

<MTIfNonEmpty tag="entrydata_poll_position">
    <mt:setvarblock name="poll_id"><mt:entrydata_poll_position></mt:setvarblock>
    <mt:IfPollIncluded poll_id="$poll_id">
        <mt:CompletePoll poll_id="$poll_id">
    </mt:IfPollIncluded>
</MTIfNonEmpty>

PollCachedChartImage

Use this tag in the Poll Position Results template to return an HTML <img ... /> tag for a cached Google Chart. This tag uses the chart options found in Poll Position: Champion’s Settings to generate the image. This tag is available in Poll Position: Champion only.

PollDisplayResults

Combine this tag with an If statement to display different poll results on your Main Index and Entry pages, for example. Supply a value in the display_results poll form element, which gets passed into the PollDisplayResults tag. Read more about the Results Template. This tag is available in Poll Position: Champion only.

PollStatus

This tag returns the numeric status of the poll in context. This tag is available in Poll Position: Champion only.

Possible values are “0” (closed for voting), “1” (open for voting) and “2” (unpublished). Use these values to control the poll display, showing only results and no voting form for polls with voting that is closed. In the code example below, the pertinent parts are bolded.

<mt:polls>
<div class="poll-container" id="poll-<mt:pollid>">
    <div id="poll-question">
        <mt:pollquestion filters="__default__">
    </div>
    <mt:If tag="PollStatus" eq="1">
    <form id="poll-form-<mt:pollid>" class="poll-form" name="poll-form-<mt:pollid>" method="post" action="" onsubmit="return submitVote(<mt:pollid>);">
        <input type="hidden" name="__mode" value="save_poll_choice" />
        <input type="hidden" name="poll_id" id="poll_id" value="<mt:pollid>" />
        <input type="hidden" name="blog_id" value="<mt:blogid>" />
        <input type="hidden" name="type" id="type_<mt:pollid>" value="poll" />
        <input type="hidden" name="results_only" value="0" />
        <div class="poll-choices">
        <mt:pollchoices>
            <div class="poll-choice">
                <input type="radio" class="poll-choice-option" id="poll-<mt:pollid>-choice-<mt:pollchoiceid>" name="poll_choice" value="<mt:pollchoiceid>" /> <label for="poll-<mt:pollid>-choice-<mt:pollchoiceid>"><mt:pollchoicetext></label>
            </div>
        </mt:pollchoices>
        </div>
        <input type="submit" class="poll-results" id="poll-submit-<mt:pollid>" value="Submit" />
        <p class="view-results"><a href="javascript:viewResults(<mt:pollid>);" id="results-text-<mt:PollID>">View results</a></p>
    </form>
    <div id="poll-results-<mt:pollid>"></div>
    <script type="text/javascript">
        checkVote(<mt:pollid>);
    </script>
    <mt:Else tag="PollStatus" eq="0">
    <p>Voting is now closed on this poll, but here are the results!</p>
    <mt:Include module="Poll Position Results">
    </mt:if>
</div>
</mt:polls>