我試圖讓每個頁面都有一個動態標題字段。CodeIgniter模板變量不能始終工作
我使用this template system庫使用CodeIgniter 2.
下面是我的開放標籤的樣品,顯示出我使用了一個名爲$title
保存當前頁面的標題變量。
$data['recaptcha'] = $this->recaptcha->get_html();
$data['title'] = "Account Registration";
$title
似乎並不在模板上作爲一個變量存在的,因爲我得到的是「CnCFPS:
<html xml:lang="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" />
我使用$this->template->write_view('content', 'path/to/view', $data');
其中$data
是一個數組寫出來的視圖|「之間的<title>
標籤。儘管如此,$recaptcha
變量完美無缺。
我試過the link above使用$this->template->write('title', 'Insert Title Here');
的例子,甚至在configs\template.php
的$ template數組中定義了一個標題。
我不知道這是怎麼回事,爲什麼它不會顯示頁面標題。
任何幫助表示讚賞,謝謝!
聽起來像它被設置爲空或什麼的。你可以運行一些代碼,看看它是否確實是空的(空($ title)?'是':'否')?也可以嘗試將名稱從$ data ['title']更改爲$ data ['foo']或其他名稱。 – Obto 2011-06-15 00:49:19
var_dump($ data)返回什麼? – starsinmypockets 2011-06-15 03:13:14
@狐狸:沒有輸出(奇怪,是) @starsinmypockets:我應該把那個放在哪裏?在視圖中還是在視圖的調用者中? – Zack 2011-06-15 19:52:20