This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Exzo
Exzo

I have a variable {{ record.title|raw }}. Trying to use it in "Title" form, but it doesnt normal output, my page have {{ record.title|raw }} title... Just :title too doesnt work. Can u help me please? Thanks!

Last updated

jan-vince
jan-vince

If you are just trying to add variable to string, in Twig you can use something like this:

{{ (page.title ~ variable)|raw }}

If this is not, what you are looking for, please be more specific with your question.

Exzo
Exzo

Jan Vince, thanks for answer, its work, but not changing title.

I have page with title Sample Page.

After page loaded, I need rename the Sample Page title to Simple Page about {{ this.page.variable }}

My English is not the best, but I think you get my point. Thank you.

Last updated

jan-vince
jan-vince

You can render and like this:

...
==
<?
function onStart(){
    $this['titleSuffix'] = ' about';
}
==
<title>OctoberCMS - {{ this.page.title ~ titleSuffix}}</title>
<meta name="title" content="{{ this.page.meta_title ~ titleSuffix }}">

This should goes to some layout, so you don't have to do this on every page.


Or try one of SEO plugins, where this is solved in much more elegant way.

Exzo
Exzo

Its work, but not like I need. I already have <title> and <meta name> tags from my Layout.

<head>
    <title>Sample Page</title>
    <meta name="title" content="">
</head>

When i add this:

<title>Sample Page about {{ this.page.title ~ record.title }}</title>
<meta name="title" content="{{ this.page.meta_title ~ record.title }}">

I already have these tags above. Is there a way to keep this layer, but override tag <title>?

jan-vince
jan-vince

Try to use placeholder like this:

Layout:

<title>
{% placeholder title default %}
    Sample page
{% endplaceholder %}
</title>

Page:

{% put title %}
    {% default %} {{ record.title }}
{% endput %}
Exzo
Exzo

Big thanks for help, its work!

1-7 of 7

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.