Issue
My CodeIgniter website's controller is set up like this:
$this->load->view('head', $data); // Contains <head> stuff
$this->load->view('header', $data); // Nav and sidebars
$this->load->view($this->uri->segment(1), $data); // Main page content
$this->load->view('footer', $data); // Footer
My question is about where to store <title>
tag's content. Ideally it would be with the page content (the 3rd loaded view) but then how do you get that into the <title>
tag which has been loaded in the first view?
I've read that it's bad to have JavaScript set the title as it won't be compatible with search engine bots.
I've also read a suggestion which said to have a large view file with all the pag
Solution
I have thought of a way to solve my issue, and I got the idea from http://joshhighland.com/blog/2008/11/09/how-i-do-layouts-and-views-in-codeigniter/. If you look on that page you can see a line like this near the bottom of the first code extract:
$layout_data['content_body'] = $this->load->view('home/homePage', $body_data, true);
This loads the view as a string into that variable. I will then run a function on that string to extract what I want the title to be (I will store it in an HTML comment) and put it into $layout_data['pageTitle']
. Then, by following the rest of the layout method on the link, I will be able to solve my issue.
Answered By - Chro
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.