Casiva Agustin

Engineering, Development and IT Management

Hi there! 馃憢

I’m Agustin Casiva, I’m a Software Engineer from Argentina.

I have been working on IT for many years now, I worked in many fields of the industry, such as hardware support, networking, sysadmin but what I do love most is development.

I have worked for many organizations, public and private, local and remote, filling many roles.

My expertise is on Web Development, Linux, Open Source, CMSs, HTML, CSS, PHP, JavaScript, Backend Development, Product Development, Project Management, Team Leading, among others.

In 2013 I have founded 42mate, a Web Development Agency focused on the design, development, maintenance of Web Apps. I still work on 42mate where I work leading development teams and scoping new projects.

Besides 42mate I also work as an independent consultant where I provide services such as

  • Development Training, for individuals or teams.
  • Architecture Design and Review.
  • Tech Advisor for non tech startup founders.
  • Tech Advisor for Digital Design Agencies.

If you are interested on my services let’s talk!

More about me

Drupal : Renderizar una Region de un Theme dentro de una tpl de Nodo

Necesitaba renderizar una region del tema dentro de la tpl de node, la idea era tener una zona para configurar bloques customizables por pagina. Googleando un poco me encuentro con una soluci贸n usando el hook preprocess node. B谩sicamente usando block_get_blocks_by_region.

function mytheme_preprocess_node(&$variables) {

  // Get a list of all the regions for this theme
  foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) {

    // Get the content for each region and add it to the $region variable
    if ($blocks = block_get_blocks_by_region($region_key)) {
      $variables['region'][$region_key] = $blocks;
    }
    else {
      $variables['region'][$region_key] = array();
    }
  }
}

Y luego dentro del node.tpl.php esto para renderizar en ese lugar los bloques

print render($region['sidebar_first']);

No funcion贸, yo hab铆a seteado los bloques por contexto, cuando pruebo por el sistema de bloques del core funcion贸. Ah铆 me di cuenta que el problema estaba en que context no se integra con la funci贸n block_get_blocks_by_region. Buscando un poco mas me encuentro con esta alternativa que usa contexto.

  function MYTHEMENAME__preprocess_node(&$vars) {
    if ($plugin = context_get_plugin('reaction', 'block')) {
      $vars['my_region_name'] = $plugin->block_get_blocks_by_region('my_region_name');
    }
  }

Esto tampoco me funcion贸 directamente, segu铆a sin renderizarme el bloque, pero esta vez por que no hab铆a content.

Buscando otra vez me encuentro que recomiendan usar drupal_static_reset(‘context_reaction_block_list’); para refrescar el cache y regenerar los bloques aclarando que puede ser un performance killer, as铆 que hice lo siguiente.

function THEME_render_region_blocks() {
  static $once = false;
  static $result = '';
  if ($once == false && $result == '') {
    $once = true; //Required to avoid recursive infinite loop rendering.
    drupal_static_reset('context_reaction_block_list');
    $plugin = context_get_plugin('reaction', 'block');
    $node_internal = $plugin->block_get_blocks_by_region('node_internal');
    $result = drupal_render($node_internal);
  }
  return $result;
}

Asi puedo renderizar la region, solo una vez y cachearla por la ejecuci贸n, y evito un loop infinito que se generaba al renderizar.

En el preprocess node me quedo algo as铆:

function THEME_preprocess_node(&$vars) { 
 $vars['internews'] = dt_get_internews();
}

 

Algunas referencias

http://www.webomelette.com/add-region-node-template
http://drupal.stackexchange.com/questions/20054/can-regions-be-printed-within-a-node-template
https://www.drupal.org/node/1306172
http://www.raisedeyebrow.com/blog/2012/07/displaying-drupal-context-regions-node-templates
http://kahthong.com/2012/08/embed-drupal-block-region-node-page
https://www.drupal.org/node/2107877

Leave a Reply

Your email address will not be published. Required fields are marked *

*