SID-00120: Would like to iterate/enumerate polls using VotePlugin
| Status: |
Answered |
TWiki version: |
4.2.4 |
Perl version: |
5.6? |
| Category: |
CategoryPlugins |
Server OS: |
Linux |
Last update: |
16 years ago |
Hi -
I'm trying to figure out how to display the results of every poll with the same "id" attribute automatically, without having to enumerate them manually. For example, I have a set of topics that all have a voting meter at the bottom (using
VotePlugin). They all have the same id. On some arbitrary page, I'd like to be able to say:
for each Topic in TopicSet{
display the current results of the vote for Topic
}
I figured out how to enumerate the topics that I want using the
TreePlugin. I also think that using that plugin, I can get the number to append to the "stars" attribute of the
VotePlugin. However, I've tried various methods, and I can't get what I want to display. I tried putting the call to
VotePlugin inside the format attribute of the
TreeView call, but that didn't display properly. Here was my raw text:
%TREE{topic="%TOPIC%" formatting="outline" levelprefix=" " startlevel="1" format="[[$topic][$spacetopic]] - $count - %VOTE{id=\"Topic voting\" stars1=\"ExampleTopic\" width1=\"10\" open=\"off\" global=\"on\" format=\"$large\" submit=\"off\"}%"}%
I tried various combinations of using escaped double quotes or using single quotes within the call to
VotePlugin, but the display always looked like this:
Example Topic - 1 - <span class= Example Topic 2 - 2 - <span class=
I tried installing the
ForEachPlugin, but encountered errors during the installation. Even if I can get it installed properly, I'm not sure if I can set, reference, and increment a counter like I would in a normal programming language.
Has anyone ever done anything like this before? Am I missing some other, more simple solution? I'm new to TWiki, but I've looked through the support forum and can't seem to find anything relevant.
Thanks for any help!
--
AuraMorris - 20 Feb 2009
Discussion and Answer
Not sure if this works, but try a VOTE within a SEARCH format. You need to escape the VOTE so that it fires off once per search hit. Untested search format:
format="[[$topic]] - $percntVOTE{id=\"Topic voting\" stars1=\"ExampleTopic\" width1=\"10\" open=\"off\" global=\"on\" format=\"$large\" submit=\"off\"}$percnt"
More at
VarSEARCH,
FormattedSearch,
SearchPatternCookbook,
QuerySearch,
VotePlugin.
--
PeterThoeny - 21 Feb 2009
I appreciate the suggestion. This seemed like it might work at first, but unfortunately I don't think it will. The problem with enumerating each of the "votes" is that for each one, you have to set an attribute called 'stars
' to the current vote name, where n is a unique number for each vote. So if I have two subtopics called "Example1" and "Example2", then I would need two calls that looked like this:
%VOTE{id=\"Topic voting\" stars1=\"ExampleTopic1\" width1=\"10\" open=\"off\" global=\"on\" format=\"$large\" submit=\"off\"}%
%VOTE{id=\"Topic voting\" stars2=\"ExampleTopic2\" width1=\"10\" open=\"off\" global=\"on\" format=\"$large\" submit=\"off\"}%
The topics can be easily enumerated, because they are subtopics with the same parent. I can also get a unique number to use in 'starsN by using the TREE function count attribute, so that seemed like a good solution. I can't get a unique number like this from the SEARCH function as far as I can tell. I did notice that your format string was a little different from my original one, so I tried using '$percnt' in front of the inner reference to VOTE to see if that fixed my formatting problem. Maybe that is why my original statement wasn't evaluating correctly? However, VotePlugin doesn't seem to recognize '$percnt' - when I use the below statement, nothing at all is displayed. Is there another way to 'escape' the percent sign? Using a backslash in front of it doesn't appear to work either._
%TREE{topic="%TOPIC%" formatting="outline" levelprefix=" " startlevel="1" format="$percntVOTE{id=\"Topic voting\" stars$count=\"$topic\" width1=\"10\" open=\"off\" global=\"on\" format=\"$large\" submit=\"off\"}$percnt"}%
-- AuraMorris - 25 Feb 2009
Well, after some more investigation, it turns out that you do not in fact have to increment 'N' in 'starsN'...at least not for separate "calls" to VOTE. So the string that worked in this instance is:
%SEARCH{"META\:TOPICPARENT.*\"%TOPIC%\"" type="regex" nonoise="on"format="$percntVOTE{id=\"Topic voting\" stars1=\"$topic\" width1=\"10\" open=\"off\" global=\"on\" format=\"$large\" submit=\"off\"}$percnt"}%
Thanks for the idea! Aura
-- AuraMorris - 25 Feb 2009
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.