How to display only the content title

Sorry for the dummy question, how do you display the name of the content folders in Kirby, but only the visible ones.

Used this which show the title but once click on a link display the title of that page. Not what I want only <?= $page->title() ?>

I’m afraid I don’t understand your question. You don’t want a link but only the page title? But then $page->title() is correct. If you don’t want a link, you have to remove the a tags around the title. But maybe you want to achieve something else. Please provide some more context.

I only want the title. But when I click a submenu the title changes to the submenu title. It should be the same title as the mean menu.

$page->title() gives you the title of the current page. So if you go to another page and display the title of that page, it will of course be the title of the subpage. Otherwise you have to display the title of the parent page $page->parent()->title() if the page has a parent. What is the use case for this?

I tried that to received error thrown with message “Call to a member function title() on null”.

<?= $page->parent()->title() ?>

Yes, that happens when the page has no parent and you have to check that, of course.

<?php if ($page->parents()->count()): ?>
<?= $page->parent()->title() ?> 
<?php else: ?>
<?= $page->title() ?> 
<?php endif ?>

Or shorter:

<?php echo $page->parents()->count() ? $page->parent()->title() : $page->title() ?>

If that doesn’t do what you want, please provide more context.

1 Like

Thank you Texnixe, that worked.