Share Your Work

Mrafey
Contributor

How to print nested content

SOLVE

Hello!

I have the following structure in the design manager:

Screen Shot 2024-03-11 at 5.26.13 PM.png
The slides field group has repeater option set to 3. So it prints out 3 questions in which each has a question text property followed by an answers group field which has its repeater options set to 3 as well which outputs 3 answers for a given question.

My issue is I am having a hard time figuring out how to access those nested answers for each question.

This is what I have thus far:

 

<div class="quiz">
	<form class="quiz-form">
		
		{% for item in module.slides %}
		<div class="question">
			<h3>{{item.question}}</h3>
			  {% for answer in slides.answers %}
			    <label>Print</label>
			    <input type="radio"/>
			  {% endfor %}
		</div>
		{% endfor %}
		
		<div class="submit-btn">
			<input type="submit" class="button"/>
		</div>
	</form>
</div>

 


Based on what I have setup 3 radio buttons with the label Test should print out for each question, but that doesn't seem to happen. I am still new to HubL and I feel I am doing the nesting incorrectly. 

Some help regarding this would be great! 

Thanks!


0 Upvotes
1 Accepted solution
Stephanie-OG
Solution
Key Advisor

How to print nested content

SOLVE

Hi @Mrafey - if you hover over the "Slides" field group and click on Actions > Copy Snippet, it should give you the code. 

 

But basically if Slides is a repeater, when you have 

{% for item in module.slides %}

 

you're now within "item", so to get the Answers you would need to have: 

{% for answer in item.slides %}

 

Something like this should work: 

<div class="quiz">
	<form class="quiz-form">
		
		{% for item in module.slides %}
		<div class="question">
			<h3>{{ item.question }}</h3>
			  {% for answer in item.answers %}
			    <label>{{ answer.answer_label }}</label>
			    <input type="radio"/>
			  {% endfor %}
		</div>
		{% endfor %}
		
		<div class="submit-btn">
			<input type="submit" class="button"/>
		</div>
	</form>
</div>

 

I hope that helps!

View solution in original post

4 Replies 4
Stephanie-OG
Solution
Key Advisor

How to print nested content

SOLVE

Hi @Mrafey - if you hover over the "Slides" field group and click on Actions > Copy Snippet, it should give you the code. 

 

But basically if Slides is a repeater, when you have 

{% for item in module.slides %}

 

you're now within "item", so to get the Answers you would need to have: 

{% for answer in item.slides %}

 

Something like this should work: 

<div class="quiz">
	<form class="quiz-form">
		
		{% for item in module.slides %}
		<div class="question">
			<h3>{{ item.question }}</h3>
			  {% for answer in item.answers %}
			    <label>{{ answer.answer_label }}</label>
			    <input type="radio"/>
			  {% endfor %}
		</div>
		{% endfor %}
		
		<div class="submit-btn">
			<input type="submit" class="button"/>
		</div>
	</form>
</div>

 

I hope that helps!

Mrafey
Contributor

How to print nested content

SOLVE

Thank you, it works! 

0 Upvotes
MattPickle
Participant | Elite Partner
Participant | Elite Partner

How to print nested content

SOLVE

This should do it. Within the loop, you access the fields for each answer group with {{ answer.<fieldname> }}.

 

{% for answer in slides.answers %}
  <label>{{ answer.answer_label }}</label>
  <input type="radio" name="{{ answer.answer_name }}" value="{{ answer.answer_value }}"/>
{% endfor %}

 

Jaycee_Lewis
Community Manager
Community Manager

How to print nested content

SOLVE

Hi, @Mrafey 👋 Thanks for your question! I'd like to invite some of our community members to the conversation   hey @Stephanie-OG @MBERARD @arinker, do you have any tips you can share with @Mrafey?

 

Thank you for taking a look! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes