Poll Position: Advanced Capabilities

Poll Position is more than the sum of its parts. A few ideas are explored below.

Per-Page Result Options

You may need to create different poll results for the Main Index and Entry archives, for example. The PollDisplayResults tag will help do this, but first you need to set a form element in the poll form. (You’ll need to use a custom poll form to add the needed input object; CompletePoll can not be used to do this.)

<input type="hidden" name="display_results" value="entry" />

display_results will be submitted with the poll, and it’s value is available in the PollDIsplayResults tag in the results template, as below.

<div class="poll-results">
    <p>PollDisplayResults tag: <mt:PollDisplayResults></p>
    <mt:If tag="PollDisplayResults" eq="entry">
        <div class="poll-result">
            <p><mt:PollChoiceText> has <mt:PollChoiceVotes> votes.</p>
<div class="poll-total">
    <p>Total votes: <span><mt:PollTotalVotes></span></p>

Quiz Correct Choice

After submitting a respons to a quiz the visitor will surely want to know if they chose correctly. The results template supplied at plugins/PollPosition/default_templates/poll_position_results.mtml includes this capability, though a brief explanation may be helpful. Refer to the following code snippet:

<mt:QuizCorrectChoiceID setvar="correct">
<mt:If tag="PollSelectedChoiceID" eq="$correct">
    <p>Correct! You've got the right answer!</p>
    <p>Sorry, wrong answer! The correct answer is <mt:QuizCorrectChoiceText>.</p>

The tag QuizCorrectChoiceID is returning the ID of the Choice selected by the author when the quiz was created. This value is saved to a variable (correct). The tag PollSelectedChoiceID contains the ID of teh Choice selected by the user when they submitted a response, and is simply compared to the saved variable which contains the ID of the correct choice.

HTML and CSS Bar Charts

Use Movable Type template tags to do the math and help generate HTML/CSS bar charts. The following code snippet works by calling the calculate_percent and supplying a numerator (with the PollChoiceVotes tag) and a denominator (supplied by the Choice with the most results and the PollTotalVotes tag), which calculates the percentages as needed.

<mt:PollTotalVotes setvar="total_votes">

<mt:SetVarTemplate name="calculate_percent">
    <mt:SetVarBlock name="percent"><mt:Var name="numerator" op="/" value="$denominator"></mt:SetVarBlock>
    <mt:SetVarBlock name="percent"><mt:Var name="percent" op="*" value="100"></mt:SetVarBlock>
    <mt:Var name="percent" sprintf="%.0f">%

<mt:Var name="graph_largest_result" value="0">
    <mt:If tag="PollChoiceVotes" gt="$graph_largest_result">
        <mt:PollChoiceVotes setvar="graph_largest_result">

<table class="poll-results" cellspacing="0" cellpadding="0" border="0">
    <mt:PollChoiceVotes setvar="choice_votes">
        <td class="poll-choice-text">
        <td class="poll-choice-scale">
            <span style="width: <mt:Var name="calculate_percent" numerator="$choice_votes" denominator="$graph_largest_result">;"></span>
        <td class="poll-choice-percent">
            <mt:Var name="calculate_percent" numerator="$choice_votes" denominator="$total_votes">
        <td class="poll-choice-votes vote-count-<mt:Var name="choice_votes">">
            <mt:Var name="choice_votes">