How To Add Individual FAQs on Every Collection Page Without Creating Separate Templates
Code mentioned in the video:
{%if collection.metafields.custom.faq.value != blank %}
<h2 class="sj-text-center">FAQ</h2>
{% endif %}
{% if collection.metafields.custom.faq and collection.metafields.custom.faq.value != blank %}
<div class="sj-faq-wrapper">
{% for item in collection.metafields.custom.faq.value %}
{% assign parts = item | split: 'ans=' %}
{% assign question = parts[0] | strip %}
{% assign answer = parts[1] | strip %}
<details class="sj-faq">
<summary>{{ question }}</summary>
<div class="sj-faq-body">
<p>{{ answer }}</p>
</div>
</details>
{% endfor %}
</div>
{% endif %}
<style>
.sj-faq-wrapper {
width: 60%;
margin: 0 auto; /* centers on desktop */
}
.sj-faq {
border-bottom: 1px solid #dadce0;
font-family: "Roboto", system-ui, -apple-system, sans-serif;
}
.sj-faq summary {
list-style: none; /* removes default triangle */
cursor: pointer;
padding: 18px 8px;
font-size: 16px;
color: #202124;
display: flex;
justify-content: space-between;
align-items: center;
transition: color .15s ease;
}
.sj-faq summary::-webkit-details-marker { display: none; } /* Safari */
/* chevron */
.sj-faq summary::after {
content: "";
width: 9px;
height: 9px;
border-right: 2px solid #5f6368;
border-bottom: 2px solid #5f6368;
transform: rotate(45deg);
transition: transform .2s ease;
margin-left: 16px;
flex-shrink: 0;
}
.sj-faq[open] summary::after {
transform: rotate(-135deg); /* points up when open */
}
.sj-faq-body {
padding: 0 8px 18px;
font-size: 14px;
line-height: 1.6;
color: #5f6368;
}
/* mobile: full width with small side padding */
@media (max-width: 768px) {
.sj-faq-wrapper {
width: 100%;
padding: 0 16px;
box-sizing: border-box;
}
}
.sj-text-center {
text-align:center;
margin-bottom:15px;
}
.sj-faq:last-child {
border-bottom: none;
}
</style>