Please I need a hand, I would like to create a new variable like the native "frontpage" variable. I have a content type called "Config", in this CT I have some boolean fields and I need check for this field values to print a view in my page.tpl
Something like this, my example field "display reviews block?", its may be set "yes" or "no". So, I need create a new variable "$display_reviews" according this value and print this in page.tpl:
<?php if (isset($display_reviews)): ?> <?php print views_embed_view('reviews', 'block'); ?> <?php endif; ?> Sincerly, I dont know how to do this, but i tried something like this:
function mytemplate_preprocess_page(&$variables) { if (isset($variables['node'])) { $n = $variables['node']; if ($variables['node']->type == 'config') { if (isset($n->field_display_reviews == 'yes') { $variables['display_reviews'] = 'this variable need be created'; } } } } UPDATE
Considering I want to print this variable in my node.tpl not in my page.tpl, I have decided to try with directly query, I dont know if is the better and fast way, but this is my code. Its not working yet, this is broking my site, but now I can display the FIELD ID. Im trying to use the field_attach_load to get the field value but no luck:
/** * Implementation of preprocess_(). */ function mytemplate_preprocess_node(&$variables, $hook) { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle', 'config') ->propertyCondition('status', 1) // value 1 from boolean field ->fieldCondition('field_display_reviews','value', '1', '='); $result = $query->execute(); if (isset($result['node'])) { $stories = $result['node']; $fields = field_info_instances('node', 'config'); // Get id of field $reviews = $fields['field_display_reviews']['field_id']; field_attach_load('node', $stories, FIELD_LOAD_CURRENT, array('field_id' => $reviews)); $output = field_get_items('node', $stories, 'field_display_reviews'); $variables['display_reviews'] = $output; } }
mytemplate? If not are you replacing it with the actual theme name?mytemplateis not my theme name, but Im aware of this. I put mytemplate as just an example.