Skip to content

Instantly share code, notes, and snippets.

@coreyaus
Last active July 28, 2023 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coreyaus/7a6368684599faec51c1e3e02c2d65bf to your computer and use it in GitHub Desktop.
Save coreyaus/7a6368684599faec51c1e3e02c2d65bf to your computer and use it in GitHub Desktop.
Theme code to replace current NationBuilder survey page templates
{% comment %}
NOTE FOR ADMINS:
If the "Show sidebar" option is selected on the settings tab of your survey page in NationBuilder
the page content appears on the left of the page and the form on the right (a two-column layout).
{% endcomment %}
<div class="container">
<div class="row row-fluid">
<div class="col-sm-6 col-lg-5 col-lg-offset-1 offset-lg-1 span6">
{% if page.headline.size > 0 %}
<h2 class="headline pb-2">{{ page.headline }}</h2>
{% endif %}
{% if page.survey.content.size > 0 %}
<div id="content">
<div id="intro" class="intro py-2">
{{ page.survey.content }}
</div>
</div>
{% endif %}
</div>
<div class="col-sm-6 col-lg-5 span6">
<div class="form-wrap">
<div class="form">
{% capture nation_slug %}{{ site.admin_dashboard_url | split: '.nationbuilder.com' | first | split: 'https://' | last | split: 'http://' | last | split:'-' | last }}{% endcapture %}{% capture nation_country_code %}{% if settings.country_code.size > 0 %}{{ settings.country_code }}{% else %}{{ settings.address.country_code }}{% endif %}{% endcapture %}{% for activity in page.activities %}{% if activity.type_name == "Survey Question Response" and activity.data.survey_question.survey_id > 0 %}{% assign last_activity = activity %}{% break %}{% endif %}{% endfor %}{% capture survey_url %}https://www.formjoy.com/form/v1/{{nation_slug}}/{{page.survey.id}}?embedded=true&page_id={{page.id}}&survey_id={{last_activity.data.survey_question.survey_id}}&latest_response_question_id={{last_activity.data.survey_question.id}}&question_ids={{page.survey.survey_questions|map:'id'|join:','}}&country_code={{nation_country_code}}&person_id={{request.current_signup.id}}&first_name={{request.current_signup.first_name}}&last_name={{request.current_signup.last_name}}&email={{request.current_signup.email}}&mobile={{request.current_signup.mobile}}{% endcapture %}
<script src="https://cdn.formjoy.com/formjoy.js"></script>
<iframe class="formjoy survey-nation" src="{{survey_url}}" onload="formJoy.init()" data-page-id="{{page.id}}" data-survey-id="{{last_activity.data.survey_question.survey_id}}" data-latest-response-question-id="{{last_activity.data.survey_question.id}}" data-question-ids="{{page.survey.survey_questions|map:'id'|join:','}}" style="box-sizing: border-box; min-width: 100%; width: 100%; overflow: hidden;" allowtransparency="true" scrolling="no" frameborder="0"><p>Your browser does not support iframes. Please visit <a href="{{survey_url}}">{{survey_url}}</a></p></iframe>
</div>
</div>
</div>
</div>
</div>
{% comment %}
NOTE FOR ADMINS:
If the "Show sidebar" option is NOT selected on the settings tab of your survey page in NationBuilder
the page content will appear directly above the survey form on the page (i.e. a single column layout)
{% endcomment %}
<div class="container">
{% if page.headline.size > 0 %}
<h2 class="headline pb-2">{{ page.headline }}</h2>
{% endif %}
{% if page.survey.content.size > 0 %}
<div id="content">
<div id="intro" class="intro py-2">
{{ page.survey.content }}
</div>
</div>
{% endif %}
<div class="form-wrap">
<div class="form">
{% capture nation_slug %}{{ site.admin_dashboard_url | split: '.nationbuilder.com' | first | split: 'https://' | last | split: 'http://' | last | split:'-' | last }}{% endcapture %}{% capture nation_country_code %}{% if settings.country_code.size > 0 %}{{ settings.country_code }}{% else %}{{ settings.address.country_code }}{% endif %}{% endcapture %}{% for activity in page.activities %}{% if activity.type_name == "Survey Question Response" and activity.data.survey_question.survey_id > 0 %}{% assign last_activity = activity %}{% break %}{% endif %}{% endfor %}{% capture survey_url %}https://www.formjoy.com/form/v1/{{nation_slug}}/{{page.survey.id}}?embedded=true&page_id={{page.id}}&survey_id={{last_activity.data.survey_question.survey_id}}&latest_response_question_id={{last_activity.data.survey_question.id}}&question_ids={{page.survey.survey_questions|map:'id'|join:','}}&country_code={{nation_country_code}}&person_id={{request.current_signup.id}}&first_name={{request.current_signup.first_name}}&last_name={{request.current_signup.last_name}}&email={{request.current_signup.email}}&mobile={{request.current_signup.mobile}}{% endcapture %}
<script src="https://cdn.formjoy.com/formjoy.js"></script>
<iframe class="formjoy survey-nation" src="{{survey_url}}" onload="formJoy.init()" data-page-id="{{page.id}}" data-survey-id="{{last_activity.data.survey_question.survey_id}}" data-latest-response-question-id="{{last_activity.data.survey_question.id}}" data-question-ids="{{page.survey.survey_questions|map:'id'|join:','}}" style="box-sizing: border-box; min-width: 100%; width: 100%; overflow: hidden;" allowtransparency="true" scrolling="no" frameborder="0"><p>Your browser does not support iframes. Please visit <a href="{{survey_url}}">{{survey_url}}</a></p></iframe>
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment