How to get the title of a page in Laravel - php

I set my title of the page like this in the blade view template:
#section('title', 'Example.com - Welcome to Example.com for all your needs')
This is working well. Now I want to know how can I access/print the current page title in the body part?
I mean for getting the current URL, we can use Request::url(). Is there a way that I can get the current page title?

I don't know of a way to do this in Laravel, but this is easily accomplished in Javascript/JQuery:
$(document).ready(function(){
console.log($("title").text());
});
Will print the title of the current page to the console. You can assign this value to an element by targeting it's id $("#id_of_element") or class $(".class_of_elemnt") and setting the text to the title's text:
$("#id_of_element").text($("title").text());
Hope that helps!

I think it's not a good idea to set the page title with hard code in layout file.
one of the best ways is to have a default page title in layout and override it in every view page.
just like below :
layout title :: {{ isset($title) ? $title : 'page title' }}

You can print your page title using
#yield('title)
wherever you want.

Related

Get the title of another page in PmWiki

I have a valid page name that I need to resolve to a page title. Example:
Main.TargetPage
(:title Page One:)
I am the page of which the title needs to be got.
Main.CurrentPage
(:title Example Page:)
I am the page that the PHP script is being run from.
How can I get the title of Main.TargetPage from Main.CurrentPage?
You can get the title of a page with this function call:
$PageTitle = PageVar(ResolvePageName('Main/TargetPage'), '$Title');
You can get the other's page title by command {Main.TargetPage$Title}, see official docs:

Contao: Frontend - Get theme section of another page - not the current page

I would need to reach a custom section by page id (or PageModel Object), but I don't find a way to get the FrontendTemplate. I would like to use it in a dropdown navigation to echo a custom section of the hovered (parent) page.
If somebody will search for, the answer is:
<?php
$articles = \ArticleModel::findPublishedByPidAndColumn($id, $column_name);
echo static::getArticle($articles[0]); // for ex. the first article
?>

How to get page title in magento?

Any way to get the page title in magento...I Have a script live person..on this I need the current page title ..So can anybodey tell me how i get the current page title?
use this code
$this->getLayout()->getBlock('head')->getTitle();
you can use this code in your phtml file
To get the title without the Prefix (site name):
<?php echo str_replace(Mage::getStoreConfig('design/head/title_prefix'), '', $this->getLayout()->getBlock('head')->getTitle()); ?>

Wordpress Navigation Label in Browser tab

I am trying to edit my header.php to call the navigation label of a page as opposed to the page title. Here is the existing code...
<title><?php wp_title( '' ); ?></title>
What is the code for calling or echoing the navigation label of a menu item?
Thanks.
What you need is to access the wp_nav_menu_objects, by first rendering the menu to extract the label in order to use it on the page title.
You can see a working solution well explained on this links:
How to get current-menu-item title as variable?
first render the menu and then display it later

Div content Page titles in Veritcal Scroll Site

Whats the easiest way to enable my page title to update per content div areas it's on?
I have a vertical scrolling website and would like the page title to change when the user navs to each content area (The content areas are within div & article)
Essentially, I'm trying to keep 'Orginal Site Title | + Home/About etc'
I'm thinking it's something I'd have to call with php to remember a set title attribute per div link? Any suggestions on setting this up (If possible)
I think you should take a look at the Viewport plugin. This way you have 4 selectors you can use:
$(":in-viewport")
$(":below-the-fold")
$(":above-the-top")
$(":left-of-screen")
$(":right-of-screen")
Now you could do something like this:
//Get the id of element(div) that is currently in view
var inview = $('div:in-viewport:first').attr('id');
//Define titles
if (inview == 'home'){
var newtitle = 'Home'
} else if (inview == 'about') {
var newtitle = 'About us'
}
//Lets rename the page title
document.title = 'Orginal Site Title |' + newtitle;
The above code should now always be called when you scroll ($(window).scroll(function () { ... });) to update page title according to the div that is currently in view.
This is just a generic example and it can be completely changed to your needs. I hope it helps in some way.
You might be able to do this by writing a plugin based on the scrollspy plugin that comes as part of twitter bootstrap: http://twitter.github.com/bootstrap/javascript.html#scrollspy
You could tweak it so rather than setting a class on the target it updates the title with whatever the content is in the current viewable panel

Categories