2012-10-11 18 views
0

我是新来的Drupal 7元标记添加到特定页面仅

我有不同的基本的页面,我使用meta标记要遍历每个页面:

<meta http-equiv="refresh" content="20; url=http://sitename/node/page2" /> 

第2页将有meta标记

<meta http-equiv="refresh" content="10; url=http://sitename/node/page3" /> 

我该怎么做?我希望元标记仅添加在基本页面上

我试着使用TEMPLATEUSED_preprocess_html添加元标记,但是我已经意识到这是错误的,因为它不是动态的并且适用于每个页面。

回答

1

drupal_add_html_head有助于向头部添加标签,请检查下面的示例。

// First, we must set up an array 
$element = array(
    '#tag' => 'link', // The #tag is the html tag - <link /> 
    '#attributes' => array(// Set up an array of attributes inside the tag 
    'href' => 'http://fonts.googleapis.com/css?family=Cardo&subset=latin', 
    'rel' => 'stylesheet', 
    'type' => 'text/css', 
), 
); 
drupal_add_html_head($element, 'google_font_cardo'); 

这将输出以下HTML:

<link href="http://fonts.googleapis.com/css?family=Cardo&amp;subset=latin" rel="stylesheet" type="text/css" /> 
1

这是一个老问题,但它仍然没有更具体的回应。看起来我们必须使用preprocess_html在template.php中添加一个head元素。 $ node不可用(至少我无法从template.php/preprocess_html中访问它),但我可以使用drupal_get_path_alias获取路径,这就是原始问题的要求。

这是我的工作例如:

function THEMENAME_preprocess_html(&$variables) { 
    if (drupal_get_path_alias() == "node/45") { 
    $meta_refresh = array(
     '#type' => 'html_tag', 
     '#tag' => 'meta', 
     '#attributes' => array( 
     'http-equiv' => 'refresh', 
     'content' => '900, url=/node/45', 
    ), 
    ); 
    drupal_add_html_head($meta_refresh, 'meta_refresh'); 
    } 
} 

使用CASE语句,可以更好地服务于沃伦的两条路径。

相关问题