0

For reference, I'm on ExpressionEngine 7 using EEHarbor's Polls add-on: https://eeharbor.com/polls/documentation

Currently, the page displaying the Poll also has a Grid field holding an image, second text "label", and larger textarea that need to display alongside the corresponding poll option. In theory, it seems like this should be easy (have the row_id match the poll option id) but I'm not sure how to make it work within the template tags logistically.

Very basically, here's the code that loops through the predefined Polls options:

{poll_options}
       <div class="poll-option">

                <div>
                    <div class="btn btn-int"><input type="button" name="option" value="CAST VOTE"></div>
                </div>

                <div>
                    <h3>{option_label}</h3>
                </div>         
              
       </div>
{/poll_options}

Which, as mentioned is already running a loop. If I simply add {grid_field} {/grid_field} just inside of the poll_options tag pair, it begins another loop through the grid rows for each poll option. If I add limit="1" to the grid_field tag, it does remove the second loop, but only uses the first grid row for each poll option.

I think this would still be a problem if I had each of the grid rows as a channel entry instead, but please correct me if that assumption is wrong.

So I'm looking for a method to run the loops "parallel," or a way to use limit="1" but increment it at the end of each poll_option loop. Can this be done with PHP? There was a sort-of similar question on here from about 7 years ago that ended up being solved with PHP but it concerned separate loops and not a loop within a loop.

2 Answers 2

0

I can't think of a direct solution right now, but one possible solution would be to display the grid contents above or below the poll, kind of like a key for a graph.

0

SOLVED (so far):

This only works if your database is "clean" and your row_id #s will match with the automatically assigned option_id # of each Polls answer "Option." If it does, you can do a 1:1 comparison of the ID numbers as follows:

{poll_options}
{grid_field}
        {if {grid_field:row_id} == {option_id}}
            <div class="poll-option" id="{option_id}">

                <div>
                    <div class="btn btn-int"><input type="button" name="option" value="CAST VOTE"></div>
                </div>

                        <h3>{option_label}</h3>
                    </div>
                </div>

                <div>
                    <h4>{grid_field:field1}</h4>
                    <p>{grid_field:field2}</p>
                </div>
                   
              
            </div>
        {/if}
{/grid_field}    
{/poll_options}

It's quite possible there's some redundant code in there but I'm not gonna look a gift horse in the mouth and try to tidy it yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.