N3riu2
April 9, 2021, 7:37am
1
Hey Friends,
i´ve a problem with showing the title of a select-field.
My Blueprint:
sektion:
label: Sektion
type: select
options: query
query:
page: programm/struktur/sektionen
text: '{{title}}'
My Template:
… <?= $page->sektion() ?> …
Output on frontend:
sektion-what-ever-name
But it should be:
Sektion what ever name
If anyone could give help or a hint, it would be amazing.
Thank you in advance!
Regards
Martin
I am a bit confused. I guess you accidentally chose the wrong question label und mean Kirby 3 not Kirby 2?
So what you are querying is your select field is structure field?
Please use three backticks before and after a code block to format your code.
N3riu2
April 9, 2021, 8:06am
3
Hey,
thanks! No, its KIRBY2.
What I want querying is the title of a select-field yes.
For Example: There are 3 pages in “programm/struktur/sektionen”
—> Sektion A
—> Sektion B
—> Sektion C
In the panel I select “Sektion A” in my select-field.
On Frontend the output is “sektion-a”. But It should be “Sektion A”.
Sorry for my bad english
Cheers!
The you have to convert the select field value into a page first.
if ( $p = page($page->sektion()->value()) ) {
echo $p->title();
}
if your select field only stores the slug, then you need to pass the complete path to the page helper
if ( $p = page('programm/strukturen/sektionen/' . $page->sektion()->value()) ) {
echo $p->title();
}
N3riu2
April 9, 2021, 8:39am
5
Thank you for you answer. But there is no output… ;(
<p>
<span>Sektion</span>
<?php if ( $sektion_title = page($page->sektio()->value()) ) {echo $sektion_title->title();} ?>
</p>
I don’t know…
N3riu2
April 9, 2021, 8:49am
7
also not working my friend
As I already wrote above, the page helper needs the full path to the page, if only section-a
is stored in your field, then the page will not be found unless you add the rest of the path.
N3riu2
April 9, 2021, 9:06am
9
still no output. I testet the path. Its correct.
<p>
<span>Sektion:</span>
<?php $sektionen = page('programm/struktur/sektionen')->children(); ?>
<?php foreach($sektionen as $sektion): ?>
<?= $sektion->title()->html() ?> <br />
<?php endforeach ?>
<?php if ( $p = page('programm/struktur/sektionen' . $page->sektion()->value()) )
{echo $p->title();} ?>
</p>
N3riu2
April 9, 2021, 9:47am
11
Works like a charme! You are an angel ;D
<?php $sektion = page('programm/struktur/sektionen/' . $page->sektio()->value()) ?>
<?= $sektion->title()->html() ?>
Have a good day!