This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I just want to share something I recently used in one of my projects...
function onEnd() {
// get the post component
$_post = $this->components['post'];
$_post = $_post->post; // post is the alias of my component
// get the title
$_title = $_post->title;
// update the page title
$this->page->title = $_title;
}
Note: the component instance on the particular page i used this script is named post - see comments in the code
Cheers
Martin
Last updated
Martin,
Just wanted to say thanks for this snippet. I'm new to October and still fumbling my way around the internals. I followed one of the video tutorials for setting up the RainLab blog plugin and the only change I had to make was change:
$_post = $this->components['post'];
to
$_post= $this->components['blogPost'];
Simply because the component alias was different. But that did exactly what I needed -- change the page title to the blog post title.
If you use Builder then to set page title as post title you should do this:
function onEnd()
{
$this->page->title = $this->components['builderDetails']->record->attributes["name"];
}
If it's not working then echo dump($this->components['builderDetails']) and see where is your post title.
you should write like this in post page :
title = "post"
url = "/blog/post/:slug"
layout = "default"
is_hidden = 0
[blogPost]
slug = "{{ :slug }}"
==
function onEnd () {
$post = $this->components['blogPost'];
$post = $postTitle->post;
if( $post ) {
$post = $post->title;
$this->page->title = $postName.' | yourSite';
}
}
==
twig section ...
Last updated
Thanks @MrCoderZ
I slightly modified the code for both the post and blog page title as follows:
Post page title:
title = "Post"
url = "/post/:slug"
layout = "yourLayout"
is_hidden = 0
[blogPost]
slug = "{{ :slug }}"
categoryPage = "blog"
==
<?php
function onEnd () {
$post = $this->components['blogPost'];
$post = $post->post;
if( $post ) {
$post = $post->title;
$this->page->title = $post.' | yourSite';
}
}
?>
==
Blog page title:
title = "yourSite"
url = "/blog/:category/:page?"
layout = "yourLayout"
is_hidden = 0
[blogPosts]
pageNumber = "{{ :page }}"
categoryFilter = "{{ :category }}"
postsPerPage = 5
noPostsMessage = "No posts found"
sortOrder = "published_at desc"
categoryPage = "blog"
postPage = "post"
==
<?php
function onEnd () {
$myblog = $this->components['blogPosts'];
$myblog = $myblog->category;
if( $myblog ) {
$myblog = $myblog->name;
$this->page->title = $myblog.' | yourSite';
}
}
?>
==
noxioustoo34847 said:
If you use Builder then to set page title as post title you should do this:
function onEnd() { $this->page->title = $this->components['builderDetails']->record->attributes["name"]; }
If it's not working then echo dump($this->components['builderDetails']) and see where is your post title.
$this->record->name;
it also works.
Last updated
noxioustoo34847 said:
If you use Builder then to set page title as post title you should do this:
function onEnd() { $this->page->title = $this->components['builderDetails']->record->attributes["name"]; }
If it's not working then echo dump($this->components['builderDetails']) and see where is your post title.
Thank you, exactly what I was looking for.
1-13 of 13