有兩種方法來解決這個問題。
首先是使用sfYaml
類更新view.yml
與默認元標記(請參閱documentation about view.yml)。之後,如果特定的頁面應該使用其他METAS你可以覆蓋默認與addMeta
method of response object
二(如ManseUK建議)是聲明插槽放置這樣的代碼到佈局
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<?php include_javascripts() ?>
<?php include_stylesheets() ?>
<?php include_title() ?>
<?php if (has_slot('metas')): ?>
<?php include_slot('metas') ?>
<?php else: ?>
<?php include_component('page', 'metas') ?>
<?php endif; ?>
<link rel="shortcut icon" href="/favicon.ico" />
</head>
<body>
默認METAS將通過page
components呈現。您的模板的頂部(我猜modules/page/templates/showSuccess.php
)處代碼
<?php slot('metas') ?>
<?php if($page->hasMetas()):?>
<!-- code to render nondefault page metas -->
<?php echo $page->getMetas(); ?>
<?php else: ?>
<?php include_component('page', 'metas') ?>
<?php endif;?>
<?php end_slot() ?>
我認爲你會與真正的代碼,將檢查您的page
對象有元標記替換$page->hasMetas()
。
其實我寧願去進一步和代碼page
部件接受參數。在模板代碼看起來像
<?php slot('metas') ?>
<?php include_component('page', 'metas', array('metas'=>$page->getMetas())) ?>
<?php end_slot() ?>
決定哪些METAS(默認或沒有)應該呈現將於page
組件(我假設你可以輕鬆地檢索defaul;從數據庫牛逼的設置)。如果沒有參數傳遞(參見佈局代碼),那麼組件也應該呈現默認元素。
我希望這會有所幫助。
你能指定你的問題嗎? – Tom 2011-05-19 20:11:03