I want to get the title of a linked page, which is linked by a twig expression.
<a href="{{ header.home.linkOne }}">#TitleHere</a>
I tried to get the title with page.find but this doesn’t work at all.
I don’t want to create a backend field to type in the title manually.
Please help me to solve this problem.
Kindly regards,
Dorian
First make sure you have this included in the frontmatter of your page:
home:
linkOne: /One
Second, try this in a Twig template:
{% set link = page.find(header.home.linkOne).url %}
{% set title = page.find(header.home.linkOne).header.title %}
<a href="{{ link }}">{{ title }}</a>
The value of linkOne needs to be the full path from the root, e.g. /home/sub-page1
.
Thanks mate. This is solved.