I have simple problem. I’ve a field in my content type (header image) that must be printed in page.tpl.php (because of layout).
It works fine, i put some code in theme_preprocess_page() function to show that field in page.tpl.php
function theme_preprocess_page( &$variables, $hook )
{
$node = menu_get_object();
if( $node && $node->type == 'page' )
{
$view = node_view($node);
$variables['headerimage'] = render($view['field_headerimage']);
}
}
Now i am having problem hiding that field_headerimage from node view. It cannot be hidden from administration ui (content types -> manage display) because if i hide it from there, it will not be available in theme_preprocess_page() either.
So i try to hide that field from preprocess_node
function theme_preprocess_node( &$variables, $hook )
{
if( $variables['page'] )
{
hide($variables['field_headerimage']);
unset($variables['field_headerimage']);
$variables['field_headerimage'] = NULL;
}
}
I added every line of code i’ve tried in removing that from being displayed. What am i doing wrong? Or: How do you hide field from theme_preprocess_node()
In
hook_preprocess_node()the content has already been built for the node object and dumped onto thecontentarray; that’s the array that will be converted to$contentin the template file, and the one you need to remove the field display from:That should get rid of it no problem.
For the sake of completeness you could also do this easily in the node.tpl.php file too:
Or in
hook_node_view()in a custom module: