Mark_E
August 8, 2023, 10:31am
1
I understand how to display a pages content on a page, using the $page variable, and site content on a page using the $site variable (Templates | Kirby CMS )
But how do I get content from one page (the homepage) to be added to several pages?
I currently have:
<meta property="og:description" content="<?= $page->description_meta_tag() ?>" />
but want it to be something like
<meta property="og:description" content="<?= $home->description_meta_tag() ?>" />
That doesn’t work. And neither does this:
<meta property="og:description" content="<?= $page->find('home')->description_meta_tag() ?>" />
These don’t work either
<meta property="og:description" content="<?= $page('home')->description_meta_tag() ?>" />
<meta property="og:description" content="<?= $page('index')->description_meta_tag() ?>" />
Is this possible?
Mark_E
August 8, 2023, 10:56am
2
Okay, this works. It seems there is a difference between page
and pages
<meta property="og:description" content="<?= $pages->find('home')->description_meta_tag() ?>" />
Okay… this must be the most basic question ever, but I’ve never dealt with it before…
Imagine this is my content-folder / site-setup;
/1-home
home.txt
/2-about
about.txt
How do I get a field-value (e.g. “intro” which contains a introduction-text) from home.txt on the about-page?
I tried several syntaxes, none of them did work…
echo $page->find('home')->intro()->kt();
echo $page('home')->intro()->kt;
It’s easy to parse the value from a field, directly linked to that page - but how do yo…
An alternative would be to use the page helper:
if ($p = page('home')) {
echo $p->title();
}
Note that you are usually better off if you make sure the desired page/file/whatever exists, before calling any member methods (like in the example).
If the object does not exist, you will get the famous calling xyz() on null error…
Mark_E
August 9, 2023, 9:46am
4
Right, got you, I simply thought if content didn’t exist, it simply wouldn’t display – rather than break the whole page.
Thanks for the tip about the page helper.