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
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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.