Drupal render() - сделать печатный контент лучше

У меня есть шаблон drupal, который отображает некоторый контент, подобный этому:

<?php $field_collection_state_info = reset($content['field_state_information']['0']['entity']['field_collection_item']);  ?>  
<?php print render($field_collection_state_info['field_state_name']); ?>

но я бы хотел запустить php ucfirst() Таким образом, весь отображаемый контент начинается с заглавной буквы.

Я попробовал это:

<?php print ucfirst(render($field_collection_state_info['field_state_name'])); ?>

Но это не сработало.

Как мне этого добиться?

Любой совет очень ценится.

С

1 ответ

Я думаю, что вам придется изменить содержимое вашего рендеринга массива перед вызовом render():

// the 'und' part is depending on the translation of the node
$field_collection_state_info['field_state_name']['und'][0]['value'] =
ucfirst($field_collection_state_info['field_state_name']['und'][0]['value']);
// render
print render($field_collection_state_info['field_state_name']);

// or you could try to modify the safe_value part of the array depending on your
// filter settings for the field
$field_collection_state_info['field_state_name']['und'][0]['safe_value'] =
ucfirst($field_collection_state_info['field_state_name']['und'][0]['safe_value']);
// render
print render($field_collection_state_info['field_state_name']); 

РЕДАКТИРОВАТЬ Попробуйте добавить это в свой template.php, он изменяет значение для поля collection_, используя hook_preprocess_node():

function YOURTHEME_preprocess_node(&$vars) {
  if($vars['type'] == 'YOUR-CONTENT-TYPE') {    
     // you might need to replace the field_content_block with the name of your field <field_state_information>
     $data = reset($vars['content']['field_content_block'][0]['entity']['field_collection_item']);
     // turn the first character to uppercase
     $data['field_text']['#object']->field_text['und'][0]['value'] = ucwords($data['field_text']['#object']->field_text['und'][0]['value']);
    // set the data in the array, like I said above your might need to change the `field_collection_block` to `field_state_information`
    $vars['content']['field_content_block'][0]['entity']['field_collection_item'] = $data;
  } 
}
Другие вопросы по тегам