I captured quotes in a “structure” field of the blueprint. The structure contains text, date, author etc.
Now I want to output this information on the page (for item in site.quotes.toStructure). I would like to use a snippet for this. How do I have to set this up so that the formatting of a quote (“>” in the panel editor) is applied?
Thank you!
In plain PHP
<?php foreach ($site->quotes()->toStructure() as $item) {
echo $item->text()->kt(); // if this is a textarea field
}
Twig (according to ChatGPT, because I don’t know)
{% for item in site.quotes.toStructure() %}
{{ item.text.kt() }} {# if this is a textarea field #}
{% endfor %}
If it is not Twig, ask ChatGPT yourself.
Hey textnixe,
Thanks for your answer.
I understood the loop (I would have to do it with Twig). But what does the inner part have to look like if I want to format text the way I do in the panel editor with the quote function?
So for example:
“Like” #author “in the year” #year “said:” #blabla
Author, year and blabla are elements within the structure.
Hm, somehow I don’t really understand what you want to achieve.
If you use
> Some quote here
in a textarea field, you can render it using the markdown() or kt() methods on the field value, like in the example I posted above.
But maybe you want to achieve something else? What is actually stored in your content.txt field now.
If you just store the text for the quote, you will have to use the proper blockquote html markup.
I’m sorry if I’m being so unclear.
If I use this code here:
{%~ if page.comments.isNotEmpty %}
{% for item in page.comments.toStructure() %}
Like {{ item.name.kt() }} says "{{ item.text.kt() }}".
{% endfor %}
{%~ endif %}
I get this raw output on the page:
Like <p>Max</p> says "<p>Once upon a time there was a frog.</p>". Like <p>Hendrik</p> says "<p>The green is so green.</p>".
Apart from the fact that I don’t want to output the HTML control characters, both entries should be formatted the way I would do it in the panel editor with the > or the quote button and separated from each other by a paragraph.
Could I please see your blueprint definition for the field and what is stored in the context file?
Sure, of course:
The blueprint:
title: Blog Post
num: '{{ page.date.toDate("Ymd") }}'
status:
draft: true
listed: true
tabs:
content:
label: Content
icon: tablo-content
columns:
- width: 2/3
sections:
content:
type: fields
fields:
text:
label: Text
type: textarea
size: large
intro:
label: Intro
type: textarea
size: large
comments:
label: Comments
type: structure
fields:
date:
label: Date
type: date
name:
label: Name
type: text
text:
label: Comment
type: textarea
size: medium
link:
label: Link
type: link
answer:
label: Answer
type: toggle
text:
- no answer
- is answer
columns:
date:
width: 1/6
name:
width: 1/6
text:
width: 1/2
answer:
width: 1/6
- width: 1/3
sections:
sidebar:
type: fields
fields:
date:
label: Published
type: date
default: now
required: true
tags:
label: Tags
type: tags
options:
type: query
query: site.childrenAndDrafts.pluck("tags", ",", true)
author:
label: Author
type: users
multiple: false
pinned:
label: Pinned
type: toggle
text:
- not pinned
- post is pinned to the top
comment:
label: Comments-Link
type: toggle
default: true
text:
- without button
- with button
files: sections/files
seo: tabs/seo
files: tabs/files
and the post.txt:
Title: Gemüse-Quiche
----
Text:
xxx
----
Intro:
----
Comments:
-
date: 2025-01-16
name: Max
text: Once upon a time there was a frog.
link: http://www.test.de
answer: 'false'
-
date: 2025-01-16
name: Hendrik
text: The green is so green.
link: ""
answer: 'true'
----
Date: 2025-01-14
----
Pinned: false
----
Comment: true
----
Meta-description:
----
Og-image:
----
Uuid: MKMRpcmwtowREJjn
Ok, so there is no quote formatting in the text, just text. So the next question is: What is your desired HTML output? What should go into the blockquote and what not?