Welcome Guest, Not a member yet? Register   Sign In
Dynamic Meta - what is the propper way to handle this?

I wanted to ask for some expert advice on handling dynamic meta tags.

I have a few pages on my site that load google maps - google maps api is called in the <head> tag. I don't want to load it on all other pages an slow down loading time for users that dont need google maps. Same with javascript, some pages load funky javascript function but others, like help section, dont really need it.

How can I include and exclude the loading of these api/javascript in the meta section (between the <head> tags) to increase the loading time for the pages that dont need these functions?

Current Solution
I have created my main meta tag view called meta_view.php - this one hold the info used on ALL pages, then created meta_maps_view.php that only has the code for loading google maps, then created meta_javascript.php to load only java functions. In building my site, I created a master view, called content_view.php to load site template with same header and footer, and dynamic content gets passed to it through $this->data['content'] = $this->load->view(view_name,TRUE).
But now, that I need to load different meta for different sections, I am forced to create multiple templates view for each meta I need, so I end up with 5-6 versions of content_view.php all loading same header and footer but different meta. Controller determines which container_view to call based on the page.
Seems a bit redundant to re-create multiple containers to load the same header and footer just because I need different meta loaded. Anybody has a better alternative?

Several solutions (well, 2 main ones really)
1. Pass an array of js and other includes, and then have the template loop through these and include them
You'd set the default ones to load (on all pages) in a MY_Controller contructor, and then add any page specific ones to that array
2. You can cheat and just echo the include directly within your controller function, this works but is a bit hacky

Ok, thanks,
One more question on the issue. If I am using a template, I load the template in controller and then load my header in the template. My controller will determine page title so using $this->data['page_title'] = "My Page", will allow me to call the page title in the template as: echo $page_title. However, if my template further loads meta as: $this->load->view('meta_view'), I can no longer use $page_title in my meta, unless I convert $page_title to array prior to loading OR load meta as include() instead of $this->load... - but this is 'hacky'. Whats your opinion?

Sorry, question is answered here: http://ellislab.com/forums/viewthread/115343/

To make the $data array available in all your views, you
You then don't need to pass the data array as a second param to the template

Theme © iAndrew 2016 - Forum software by © MyBB