Displaying dynamic Title

Hi there,

i am new at October CMS and PHP and twig, so sorry in advanced :slight_smile:

I use {{ this.page.title }} in my default.htm Layout. It works fine. Now i have a {{ record.name }} and i wanna display these dynamic titles.

url = "/projects/:id"
layout = "default"
title = "{{ record.name }}"

[builderDetails]
modelClass = "Yaseed\RoofPro\Models\RoofPro"
identifierValue = "{{ :id }}"
modelKeyColumn = "id"
displayColumn = "project name"
notFoundMessage = "No projects found"
==
<h1 class="text-3xl font-bold tracking-tight text-gray-900">Project name: {{ record.projectname }}</h1>
<h2 class="text-2xl font-semibold text-gray-800 mt-4">Project description:</h2>
<p class="mt-2 text-lg text-gray-700">
    {{ record.project-description }}
</p>

that would be too simple and doesn’t work either. I’ve already tried a few things from Stackoverflow, but unfortunately I haven’t found anything useful. How do I get on with this?

Ok i think i got it:

url = "/projekte/:id"
layout = "default"
title = "Single Projekt"

[builderDetails]
modelClass = "Yaseed\Dachpro\Models\DachPro"
identifierValue = "{{ :id }}"
modelKeyColumn = "id"
displayColumn = "projektname"
notFoundMessage = "Keine Projekte gefunden"
==
function onEnd()
{
    $record = $this->components['builderDetails']->record;
    $this->page->title = $record->projektname;
    $this['record'] = $record;
}
==
<h2 class="text-2xl font-semibold text-gray-800 mt-4">Projektbeschreibung:</h2>
<p class="mt-2 text-lg text-gray-700">
    {{ record.projektbeschreibung }}
</p>

Is this workaround good? It works, but what can i improve?

maybe simplier

# in your page
{% put pageTitle = record.name %}

# in your layout
{% set placeholderTitle = placeholder('pageTitle') %}

<title>{{ pageTitle }}</title>
<meta name="title" content="{{ pageTitle }}">
1 Like