CodeIgniter Template variables not working all the time
I'm trying to allow each of my pages to have a dynamic title field.
I'm using this template system library with CodeIgniter 2.
Below is a sample of my opening tags, showing that I'm using a variable called $title
to store the current page's title.
<html xml:lang=开发者_如何学JAVA"en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>CnCFPS <?php echo "| $title"; ?></title>
<meta http-equiv="Content-Language" content="en" />
<meta name="Description" content="Todo" />
<meta name="Keywords" content="Todo" />
I'm writing it out to the view using $this->template->write_view( 'content', 'path/to/view', $data' );
in which $data
is an array:
$data['recaptcha'] = $this->recaptcha->get_html();
$data['title'] = "Account Registration";
$title
seems to not exist on the template as a variable because all I get is "CnCFPS | " between the <title>
tags. The $recaptcha
variable works perfectly fine though.
I've attempted the example on the link above using $this->template->write( 'title', 'Insert Title Here');
and even defined a title in my $template array from configs\template.php
.
I don't know what's up with this and why it won't display the page title.
Any help is appreciated, thanks!
a few things to try.
instead of using $data['title'] use $this->data['title']
and call $data['title']
for the title instead of $title.
you'll have to change all $data arrays in the function to be $this->data[]
.
And the other thing, stupid but escape out your variable. Its best practice.
<title>CnCFPS<?php echo " | ".$title; ?></title>
精彩评论