Last active
August 29, 2015 14:20
-
-
Save ejucovy/82f1835ad4e684333b14 to your computer and use it in GitHub Desktop.
ActionKit quiz code snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"eighth_president": "Martin van Buren", | |
"us_capital": "Washington, DC", | |
"war_end": "1814" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if page.custom_fields.interactive_quiz_responses %} | |
{% with page.custom_fields.interactive_quiz_responses|load_json as answers %} | |
{% with "[]"|load_json as score %} | |
{% for question in form.surveyquestion_set.all %} | |
{% if answers|nth:question.field_name == action.custom_fields|nth:question.field_name %} | |
{% record question.field_name in score %} | |
{% endif %} | |
{% endfor %} | |
<h3 style="margin-top: -15px; margin-bottom: 15px">Your score: {{ score|length }} out of {{ form.surveyquestion_set.all.count }}</h3> | |
{% endwith %} | |
{% for question in form.surveyquestion_set.all %} | |
<div style="margin-bottom: 25px" class="span50 input-parent {{ question.question_label|slugify }}"> | |
<label><strong>{{ question.question_label }}</strong> | |
</label> | |
<div>The answer was <strong>{{ answers|nth:question.field_name }}</strong>. | |
</div><div>You were | |
{% if answers|nth:question.field_name == action.custom_fields|nth:question.field_name %} | |
<span style="color: green">CORRECT!</span> | |
{% else %} | |
<span style="color: red">wrong.</span> | |
{% endif %} | |
</div><div>(<em>You said: {{ action.custom_fields|nth:question.field_name }}</em>)</div> | |
</div> | |
{% endfor %} | |
{% endwith %} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment