Hello.
I have big problem in my template, can someone help to understand what’s wrong?
- I have simple pages collection, like this:
<?php $news = $site->find("news")->children()->listed(); ?>
- I go thru them in foreach:
<?php foreach ($news as $news_item) : ?>
...
<?php endforeach; ?>
- I have field
linkto_theme
in my$news_item
page object, and can get it with no problem like this:
<?= $news_item->linkto_theme(); ?>
This field in blueprints is simple multiselect field, where I selecting other pages to “linking them” to my news page.
-
It returns other page ID for me, like
otherpage
. -
So there is I falling in troubles:
a) there is no way to get "label of this otherpage
value, because it page’s ID, not blueprint value.
b) Ok, I can use API and get this page title by using somtehing like
dump(page('otherpage')->title());
c) It works perfect, but I need it in “dynamic” - there is more than one news
page in my collection, and there is someother
and somethirdpage
values in next collection page objects.
d) Logically I can use something like this:
dump(page($news_item->linkto_theme()->toString()));
where
$news_item->linkto_theme()->toString()
is an argument (other page’s id) getted “dynamically” from field value,
but it works ONLY ONCE!
When I increase limit to 2+, there is no error, but dump returns me only FIRST page’s dump in collection.
e) And there is other problem -
page($news_item->linkto_theme()->toString())
returns me a Page object, but
page($news_item->linkto_theme()->toString())->title()
wont work too on more than one page collection!
It returns me
Kirby\Cms\Field Object
(
[title] => My Other Page Title
)
when I set collection limit to 1, but throws me an error when I set collection limit to 2+ !!!
Error
Call to a member function title() on null
I broke my brain, please someone help me, what I did wrong?
I think this is simple logical way - go thru pages collection, get some field values as other page’s ids and get titles from this ids and print it to template etc. ?!
Thank you very much.