Liqiud basics
Modules
API
Mailer
Surveys
Overview
Below you can see all the available drops on the survey object
| Name | Description |
| survey.id | |
| survey.name | |
| survey.url | |
| survey.locale | |
| survey.site_id | |
| survey.version | |
| survey.start_at |
|
| survey.end_at | |
| survey.can_take? | Returns true if thesurvey's start_at is in the past and its end_at is in the future. |
| survey.questions | Array with survey question objects |
Templates
To create a template for a survey, use the following (depending on what template you need):
| Name | Description |
| surveys.{survey.url}.single.tpl | For a specific survey |
| surveys.single.tpl | For general survey |
| surveys.{survey.url}.opportunities.single.tpl | For specific opportunity |
| surveys.opportunities.single.tpl | For general opportunity |
| surveys.{survey.url}.opportunities.single.pdf | PDF for specific survey |
| surveys.opportunities.single.pdf | PDF for specific opportunity |
URL
To access a template for a survey or opportunity, you can use the following:
/s/{surey_url}
/s/{surey_url}/o/{id}
/s/{surey_url}/o/{id}.pdf
Snippets
General
To loop through all existing surveys for the current locale we use:
{% for survey in site.surveys %} <p>{{ survey.name }}</p> {% endfor %}
Create survey opportunity
Posting answers for a suryvey can be done throught the API endpoint: /api/v1/surveys/:survey_id/survey_opportunities
Incoming params schema:
whoami: john@doe.com (only needed if not authorized as customer_account)
answers:
{:question_id}: "My answer"
Example of generated form:
{% for survey in site.surveys %}
<form action="/api/v1/surveys/{{ survey.id }}/survey_opportunities" method="post">
<h1>{{ survey.name }}</h1>
{% for q in survey.questions %}
<h3>{{ q.text }}</h3>
{% for o in q.options %}
{% if q.option_type != 'select' %}
<label>
<input type="{{ q.option_type }}" name="answers[{{q.id}}]" value="{{ o.text }}"> {{ o.text }}
</label>
{% endif %}
{% endfor %}
<hr>
{% for subquestion in q.questions %}
{% for o in subquestion.options %}
{% if subquestion.option_type != 'select' %}
<label>
<input type="{{ subquestion.option_type }}" name="answers[{{subquestion.id}}]" value="{{ o.text }}"> {{ o.text }}
</label>
{% endif %}
{% endfor %}
{% endfor %}
<button type="submit">Send</button>
{% endfor %}
</form>
{% endfor %} $('form').on 'submit',(e) ->
e.preventDefault()
$.ajax
url: $(this).attr('action')
method: 'POST'
data: $(this).serialize()
success: (data) ->
console.log 'Survey opportunity sent'
error: (jqXHR, textStatus, errorThrown) ->
console.log 'Something went wrong'Updated: 2021-12-15