Share Your Work

Mrafey
投稿者

How to print nested content

解決

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 いいね!
1件の承認済みベストアンサー
Stephanie-OG
解決策
キーアドバイザー

How to print nested content

解決

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!

元の投稿で解決策を見る

4件の返信
Stephanie-OG
解決策
キーアドバイザー

How to print nested content

解決

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
投稿者

How to print nested content

解決

Thank you, it works! 

0 いいね!
MattPickle
参加者 | Elite Partner
参加者 | Elite Partner

How to print nested content

解決

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
コミュニティーマネージャー
コミュニティーマネージャー

How to print nested content

解決

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 いいね!