目前我将主页标题设置为页面名称但是对于主页我想将其设置为不同的“标题”,但我不想改变数据库中的“标题”,因为这影响URI和<title>
。在视图中,我只想更改单个h1
标记
我是否可以使用if else语句更改以下代码,以确定页面是否为= home然后显示welcome welcome else继续并显示页面名称?
public function index()
{
$page = $this->uri->segment(2, FALSE);
if (!$page)
{
die(' wrong permalink in DB'); //show_404();
}
else
{
$page = $this->navigation_model->getCMSPageByPermalink($page);
$data['cms_pages'] = $this->navigation_model->getCMSPages();
$data['title'] = $page->name;
$data['class'] = $page->permalink;
// put all page templates in the 'views/templates' dir to keep it tidy
// load in my whole page object, allows me to access the variables directly.
$data['content'] = $this->load->view('templates/'. $page->template, $page, TRUE);
$this->load->view('template',$data);
}
}
}
答案 0 :(得分:2)
试试这个
$data['title'] = ($page->name == 'Home' ? 'Welcome' : $page->name);