Welcome Guest, Not a member yet? Register   Sign In
SEO / Pass variable from controller through MYcontroller to view template
#1

[eluser]tecrik[/eluser]
Ok, so this is probably a trivial problem, but I don't really know how to get it done. I want to assign meta tags to each of my controllers and/or the functions of those. My plan was, to include something link this in either the Constructor and/or the respective function(s):

Code:
$this->data = array(
    'titletag'         => "Your title tag here",
    'metadescription'     => "Your page's description here",
    'metakeywords'         => "keywords, keywords, keywords",
    'pagetitle'        => "Tampa Business Directory",
    'content_view'         => null,
    'content_data'        => ''
);

For the views, I have a function view_template in MYController to include other template parts etc, so whenever I call a view it kinda looks like this:

Code:
$content = $this->parser->parse('produkte/template', array('produkte' => $query), true);
$this->view_template($content);

In the view_template function I can define a variable such as

Code:
$data['titletag'] = 'title tag is working';

and then call it in my actual template using

Code:
<?=$titletag;?>

What won't work is this

Code:
$data['titletag'] = $titletag;

The question now is, how to pass the variable or rather all variables all the way through from the controller to the view_template function in MYcontroller on to the actual template/view.

If you have any other advice on how to do SEO with CI and make things a little easier, I am open for suggestions!

Thanks so much in advance!
#2

[eluser]tecrik[/eluser]
I forgot, it's not in my code but I tried passing $data through as a parameter, when parsing the content or calling the view_template. That didn't work for me.
#3

[eluser]InsiteFX[/eluser]
Hi,

Code:
$data['titletag'] = $titletag;

try setting $titletag to a value ie: $titletag = "my title";

Enjoy
InsiteFX
#4

[eluser]tecrik[/eluser]
That's what I am trying to do. Just not in the MYController file but in the controller before that. It kind goes like this:

Controller (here I want to define title/meta variables e.g. $titletag="my title"

|

MYController (here I have got the view_template function to call the template, here I want to call the variables from the controller to pass them on to the template e.g. $data['titletag'] = $titletag )

|

Template (here is where I want to actually include the variables e.g. <?=$titletag;?&gtWink


EDIT: Just passing information from the view_template function in MYController to the template already works like this: $data['titletag'] = 'my title'. My problem is the connection between the individual controllers and the view_template function in MYController.




Theme © iAndrew 2016 - Forum software by © MyBB