# Schema.org FAQ utility

![Example Schema.org structure that it generated](https://825756965-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_zivnvKch6re2urR-L%2F-MYfJbmogAW1XDhkykef%2F-MYfJjH2E3cD6Khgavh5%2FScreen%20Shot%202021-04-19%20at%2011.09.00%20AM.png?alt=media\&token=8d970340-12ba-47fa-ab84-ab47318f61cc)

## Basic usage example

`faq_items` in this example is hard-coded. But you would replace with your own data fields.

```markup
{% set faq_items = [
    {
        'answer_text': 'Answer to question 1',
        'question_name': 'Question 1?'
    },
    {
        'answer_text': 'Answer to question 2',
        'question_name': 'Question 2?'
    }
] %}

<script type="application/ld+json">
{{ faq_items|as_faq_schema|tojson|safe }}
</script>
```

## Using custom field data example

Looping over some custom field values to generate the FAQ items.

```markup
{% set faq_items = [] %}
{% for i in range(1, 5) %}
  {% set title_value_key = 'faq_title_text_%s' % i %}
  {% set description_value_key = 'faq_description_text_%s' % i %}
  {% if site.custom_fields[title_value_key] %}
    {% do faq_items.append({
        'question_name': site.custom_fields[title_value_key],
        'answer_text': site.custom_fields[description_value_key]
    }) %}
  {% endif %}
{% endfor %}

<script type="application/ld+json">
{{ faq_items|as_faq_schema|tojson|safe }}
</script>
```
