We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

LG Polls: Only show chart when {if_show_results} true

Development and Programming

Bluebloc's avatar
Bluebloc
111 posts
16 years ago
Bluebloc's avatar Bluebloc

Does anyone know how to set up LG Polls only to show the results Pie Chart when {if_show_results} variable is true?

My poll is set up using the ajax templates and all is working fine. The problem is when I add the {exp:lg_polls:chart} tag code to the main poll template the results chart always show up regardless of poll settings. Also the {exp:lg_polls:chart} tag seems not to recognise {if_show_results}.

If I add the {exp:lg_polls:chart} to _components/_poll or _components/_ajax_poll it breask the templates giving mysql errors etc.

What is the correct way to only show a pie chart based on the {if_show_results} variable?

Thanks

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
16 years ago
Leevi Graham's avatar Leevi Graham

Hey Bluebloc,

I replied to your email but I’ll add my response here as well.

I originally coded LG Polls to minimise the amount of processing needed when the user couldn’t vote. As such I checked if the user could or could not vote and then rendered the poll. Although this reduces the processing it also is not obvious to the template designer.

The following code is in mod.lg_polls.php in the poll function:

// render the results answers
// we do this first as they are already in order
if($this->conditionals['show_results'] === TRUE)
{
    // then render the answers
    $this->_render_answers('results');
}

if($this->conditionals['can_vote'] === TRUE)
{
    // render the form
    $this->_render_form();
    // sort the answers so they are the same as the publish form
    $this->poll->sort_answers();
    // render the form tags
    $this->_render_answers('poll');
}

To remove the check in the code update it to:

// render the answers
$this->_render_answers('results');
// render the form
$this->_render_form();
// sort the answers so they are the same as the publish form
$this->poll->sort_answers();
// render the form tags
$this->_render_answers('poll');

Basically all you are doing is removing the checks first and rendering the polls regardless of the conditional tags.

Your {if can_vote} conditionals will still work as expected inside your template.

       
Bluebloc's avatar
Bluebloc
111 posts
16 years ago
Bluebloc's avatar Bluebloc

Thanks Leevi. That’s sorted it out for me.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.