Forum
FAQ using two page list & detail - Blocks
I've been struggling with this for a while. I've used the Two Page List & Detail tutorial to create an FAQ page on my site. Ive used tabbed content so that the user can show/hide a section to view categories and questions within that section, the structure goes like this:
- 3 Main sections as tabs (e.g. General | Consumers | Physicians)
- Within each of the tabs there are multiple sections (i.e. General > Getting Started | General > Security & Privacy)
- Within each section there are multiple questions which have associated answers (i.e. General > Getting Started > Where do I download x?)
I've set up two templates, one for Questions and one for Answers and they are working as they should when I only add one question and answer, but I've tried using blocks to allow multiple sections as described above and the output is blank. I've also tried scope-parent="true"
but that didn't have any effect.
Is it possible to use blocks or repeaters within a template created using perch_content_create
?
Help Page (showing all questions in the tabbed content):
<?php perch_content_create('Help - '.$lang, array(
'template' => 'Help-Answer.html',
'multiple' => true,
'edit-mode' => 'listdetail',
));?>
<?php perch_content_custom('Help - '.$lang, array(
'template' => 'Help-Question.html',
));?>
Solution Page (showing the question and answer when user clicks on a question in help page):
<?php perch_content_custom('Help - '.$lang, array(
'page' => '/help.php',
'template' => 'Help-Answer.html',
'filter' => 'slug',
'match' => 'eq',
'value' => perch_get('s'),
'count' => 1,
));?>
Question template
<li class="tab-header-and-content">
<a href="javascript:void(0)" class="<perch:if exists="perch_item_first">is-active</perch:if> tab-link">
<perch:content id="helpSectionHeading" type="text" label="Tab Heading" />
</a>
<div class="tab-content">
<h4><perch:content id="helpContentHeading" type="text" label="Section Heading" /></h4>
<a href="solution?s=<perch:content id="slug" type="slug" />">
<p><perch:content id="helpContentQuestion" type="textarea" size="xs" label="Question" /></p>
</a>
</div>
</li>
Answer template
<perch:content id="helpSectionHeading" type="text" label="Tab Heading" suppress="true" />
<perch:blocks>
<perch:block type="helpSectionBlock" label="Help Section">
<h4><perch:content id="helpContentHeading" type="text" label="Section Heading" suppress="true" /></h4>
<p><perch:content id="helpContentQuestion" type="textarea" size="xs" label="Question" /></p>
<perch:content id="slug" for="helpContentQuestion" type="slug" suppress="true" />
<p><perch:content id="helpContentAnswer" type="textarea" size="xs" label="Answer" /></p>
</perch:block>
</perch:blocks>
Yes, absolutely.
Which template is blank?
Hi Drew, thanks for the response.
If I use the above 'Answer template' but without the blocks, then the content displays on the Help Page via the 'Question template' as it should, but I cant add multiple sections of questions & answers.
However as soon as I add blocks to 'Answer template' (as shown above)
id="helpContentQuestion"
is no longer output on the help page, just empty p tags. Its like the ID's become out of scope when inside blocks?.. I'm not sure how IDs work across a site?If you're using blocks, you need to include the blocks tags whenever they're used. Are you doing that?
Ah, so blocks tags need to be used in both the Question Template and the Answer Template?
They need to appear anywhere you're using the blocks. Blocks don't work without the
<perch:blocks>
tags.Understood, but are you also saying that if an id is referenced inside blocks in one template...
e.g.
id="helpContentQuestion"
is inside blocks tags in the Answer Template above... then it also needs to be within blocks tags when being re-used in another template..
e.g.
id="helpContentQuestion"
is currently not inside blocks tags in Question Template above, which is causing the error?To get to values outside of the blocks, you need to bring those into scope:
and then use
id="parent.helpContentQuestion"