Proper way for controlling meta tags. |
[eluser]mTuran[/eluser]
In my web site have some meta tags like description or keywords sure. I want to change them from controllers dynamically one way to do that is: Code: <title><?=$page_title;?></title> Code: $data['page_title'] = 'Bla bla bla'; This way works but i don't think it is proper way because if i want to write nothing to page_description and not write $data['page_description'], there will be occur notice errors. I have a idea. I think if i code meta library and add to auto load, i can easly control meta tags like $this->meta->set_desc('bla bla bla'); Is this proper way ? Thank you
[eluser]Maglok[/eluser]
I think the most 'proper' way CI has of handling this is the html helper meta() function: http://ellislab.com/codeigniter/user-gui...elper.html
[eluser]mTuran[/eluser]
i think you didn't understand my question. meta helper helps you for generate meta tags easily. my question is which way is proper for include my view.
[eluser]Maglok[/eluser]
I'd say put this in your controller: Code: $meta = array( Listing whatever you want. Then use the html helper to generate them in your viewer like so: Code: <?php echo meta($meta); ?>
[eluser]mTuran[/eluser]
if i don't declare $meta variable in my controller, there will be occur php notice error. Am i wrong ? I will use this helper in my library. Point of i want to write library is if i don't declare any meta tag, library will handle it and there will be not php notice error.
[eluser]Maglok[/eluser]
Use a IF construction? Something like: Code: <?php if(isset($meta)) {
[eluser]mTuran[/eluser]
is using if conditions in views a good chioice ? I think it's a bit of hacky. Thanks
[eluser]Phil Sturgeon[/eluser]
Perhaps the shorter syntax of: Code: <?php echo meta(@$meta); ?> or Code: <?php if(isset($meta)) meta($meta); ?> or Code: <?=isset($meta) ? meta($meta) : ''; ?> How did I miss the meta helper? I will have to use this in my code instead of my rather limited meta string calculations based on name in my layout library.
[eluser]Maglok[/eluser]
It's 'hidden' in the html helper. I guess it is the best place for it, but not very obvious. Easy to miss, very usefull though, VERY usefull.
[eluser]mTuran[/eluser]
i will use meta(@$meta); thanks. I have one more little question. My default layout like that Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> If one day i decide to add one more variable to my default layout view then i have to edit all of my controllers because of notice error. I don't understand this side of MVC. Thanks |
Welcome Guest, Not a member yet? Register Sign In |