Fandom

Community Central

Comments5

Editable Polls

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

This is another small wikicode trick, that can be very useful in some situations, but also allows poll result manipulation. It's a trick to make polls editable.

Prerequisites for this guide are the knowledge of using and creating templates.

What are polls?

If you don't know polls at all, here is a short introduction:

Did you ever create an own poll?
 
14
 
2
 
1
 

The poll was created at 13:09 on April 16, 2016, and so far 17 people voted.

This is a poll. Everyone, including anonymous users, can vote in it. All votes are anonymous. The wikicode for it looks like this:

<poll>Did you ever create an own poll?
Yes
No
I'm not sure
</poll>

The first line is the question, every other line is a new option. Make sure to use the source edit mode for it to prevent double newlines.

The Limitations

Polls have one small limitation: If you change the content (for example to fix a typo in the question or to add another option), this will be seen as a new poll and all votes will be reset to 0.

The Trick

I found one trick to circumvent this: Usage of templates! If the content of a poll is a template, then the template can be edited and the poll won't be reset.

Now, you usually don't want to create a new template for every poll. So here is another trick: Use transclusion to use the page where the poll is as a template itself! There are two ways to do that:

  • Encapsulate the template part of the page with both <includeonly> and <onlyinclude> tags. This will make sure the page itself does not include the template and the template does not include the rest of the page.
  • Alternatively, encapsulate the template part with the <includeonly> and all the rest of the page with the <noinclude> tags. This has exactly the same effect.

Now put all lines inside the poll in the template part and use the template between the poll tags. This is some example code for a page that uses this trick:

This page features an editable poll
<poll>{{Namespace:NameOfThisPage}}</poll>
<includeonly><onlyinclude>Is this poll editable?
Yes
No
</onlyinclude></includeonly>
Where "Namespace:NameOfThisPage" has to be replaced by the correct name. Leave the namespace empty (but don't remove the colon) if you are in the article (Main) namespace.

After editing the poll template, you might have to purge the page to see the results.

Going Further

The code shown above means the page can include only one editable poll, because every usage as template will have a different result. The following code will solve this problem too. I won't go into further detail on this one, except for a link to the used #switch parser function.

<poll>{{Namespace:NameOfThisPage|poll1}}</poll>
<poll>{{Namespace:NameOfThisPage|poll2}}</poll>
<poll>{{Namespace:NameOfThisPage|poll3}}</poll>
<includeonly><onlyinclude>{{#switch:{{{1|}}}
|poll1=Question 1?
First option of Q1
Second option of Q1
|poll2=Question 2?
First option of Q2
Second option of Q2
Third option of Q2
|poll3=Question 3?
You know what goes here...|}}
</onlyinclude></includeonly>

The Result

The following polls are all editable. Tell me in the comments if you want an option added.

What is your favorite fruit?
 
4
 
3
 
4
 

The poll was created at 14:03 on April 16, 2016, and so far 11 people voted.
What is the answer to live, the universe, and everything?
 
0
 
6
 
1
 
3
 
0
 

The poll was created at 14:03 on April 16, 2016, and so far 10 people voted.
Is this blog well written and understandable?
 
3
 
6
 
2
 
0
 

The poll was created at 14:03 on April 16, 2016, and so far 11 people voted.

Also on Fandom

Random Wiki