{% for pin in pinned_history %}
  {% if template_params and template_params.max_pinned_messages %}
    {% if loop.index <= template_params.max_pinned_messages %}
- name: "pin_{{ loop.index }}"
  content: |
    {{ settings.start_token }}{{ escape_special_characters(pin) }}{{ settings.eom }}
    {% set settings.start_token = settings.bom %}
    {% endif %}
  {% else %}
- name: "pin_{{ loop.index }}"
  content: |
    {{ settings.start_token }}{{ escape_special_characters(pin) }}{{ settings.eom }}
    {% set settings.start_token = settings.bom %}
  {% endif %}
{% endfor %}
