Drupal Change Page Title Template
And you can't do the [page-number] in your global or you get 'Page 1' in the title of every page. It does not works when sorting pages Posted by tcibah on May 1, 2011 at 4:57pm. * * The doctype, html, head and body tags are not in this template. Instead they * can be found in the html.tpl.php template. Surprisingly there is no option in the admin interface to change the title of the blog page which is generated by the blog module. Though you can change the title by changing the menu link. But sometimes you probably want to keep the menu link, but change the blog title or you want to have different titles in the menu and on the page.
I want to programmatically alter a page title in Drupal 8 so that it will be hard-coded in the theme file.
I'm attempting to use a hook function to preprocess_page_title, but it seems to not understand what page to change the title on.
Here's what I have so far:
I figured the only way to make this change on one specific page is to set the node argument. Has any one figured out a way to override page title on Drupal?
3 Answers
In your template.theme file add the preprocessor and then override page-title.html.twig in your template folder by printing the variable, like below:
then {{ subtitle }}
Here's the method to preprocess your page :
and in your template page.html.twig
There are a couple of solutions to change the page title
On template
On the node view page
for a sample if you want to change user title
On Controller or hook_form_alter
Yusef MohamadiFacebook Change Page Title
Yusef MohamadiNot the answer you're looking for? Browse other questions tagged webdrupalnodesdrupal-8preprocessor or ask your own question.
Today I've try to add image_field in 'Page Title' block.
I don't know if it's possible ?
If it isn't possible, it is possible to add field_image in twig template ?
Tnks.
1 Answer
The below may help you. First im adding a theme suggestion for page_title, so that i can control the place where i have to over ride the template. I am adding node_type - as suffix to the template.
Then i am adding the preprocess function- make sure you replace the signature with the type you want 'news' at the end should be replaced with your content type from the first function.
In the second function i am fetching a field called subtitle, and adding the value to variables so that it is available in the template.
Now in the template you will sub_title available in the template file, in my case it was page-title--news.html.twig - copied from page-title.html.twig and added respective variable.