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!