簡體   English   中英

使用theme_preprocess_field()更改字段

[英]Change field using theme_preprocess_field()

gunwinner是我的主題名稱,我想更改特定內容類型的字段。 我已經嘗試過此代碼,

function gunwinner_preprocess_field(&$variables) {
  $element = $variables['element'];
  if($element['#field_name'] == 'field_deal_url') {
     $values = $element['#items'][0]['value'];
     $deal_link = l(t("Go to Store"), "$values", array('attributes' => array('class' => 'store-link')));
     $element['#items'][0]['value'] = "Store";
  return;
  }
}

這會返回帶有鏈接標題“轉到商店”的數組,但它不會反映在特定字段的頁面上。

有人可以幫我嗎?

您正在復制$variables['element']並對其進行操作,因此更改不會保留在原始變量中。

只需將函數的第一行更改為

$element = &$variables['element'];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM