hi

i would to convert my D6 themes into D7 but i cant add custom region in node-custom.tpl like for D6
i start from the D7 basic theme

in D6 i've in template.php :

<?php
function cyrano_ca_preprocess_node(&$vars, $hook) {
//Partie regions dans node.tpl- ajoute les regions utiles au node.tpl
 $vars['pole_bloc_G'] = theme('blocks', 'pole_bloc_G');
 $vars['pole_bloc_C'] = theme('blocks', 'pole_bloc_C');
 $vars['pole_bloc_D'] = theme('blocks', 'pole_bloc_D');
 $vars['col_G1'] = theme('blocks', 'col_G1');
 $vars['col_G2'] = theme('blocks', 'col_G2');
 $vars['col_G3'] = theme('blocks', 'col_G3');
...
?>

in D7 i try but it's not work,which function to choose ? :

<?php
function cyrano_er_d7_preprocess_node(&$vars) {
  
  /* Permettre l'ajout de regions dans les node.tpl pour le theming de node
 * http://www.victheme.com/blog/drupal-7-printing-block-region-nodetplphp
 */
        if ($blocks = block_get_blocks_by_region('region')) {
      $vars['colonne_c1'] = $blocks;
      $vars['colonne_c2'] = $blocks;
      $vars['colonne_c3']['#region'] = 'Colonne C3 - Theming de node';

  }
// Add a striping class.
  $vars['classes_array'][] = 'node-' . $vars['zebra'];
}

function cyrano_er_d7_preprocess_block(&$vars, $hook) {
  // Add a striping class.
  $vars['classes_array'][] = 'block-' . $vars['zebra'];
}?>

if someone could explain how to do..thanks

Comments

nevets’s picture

The two pieces of code are very different, since you do not say what does it work it is hard to provide a suggestion. I can point out that

      $vars['colonne_c1'] = $blocks;
      $vars['colonne_c2'] = $blocks;

is likely to cause problems is you print both variables in node.tpl.php since that would produce the same blocks twice resulting in duplicated css id's which should be unique.

Also, it may be possible to use Display Suite or Panels to produce the same results.

aiphes’s picture

so this would be better ?

<?php
$vars['colonne_c1']['#region'] = 'Colonne C1 - Theming de node';
$vars['colonne_c2']['#region'] = 'Colonne C2 - Theming de node';
$vars['colonne_c3']['#region'] = 'Colonne C3 - Theming de node';
?>

in D6 i use

<?php //regions pour inserer un bloc dans la colonne G2
if ($col_G2): ?>
    <?php  print $col_G2; ?>
<?php endif; ?>

to include a region in a node-custom.tpl..so i would do the same for D7, but do i modify the php like this ?

<?php //regions pour inserer un bloc dans la colonne G2
if ($page ['col_G2']): ?>
    <?php  print render ($page ['col_G2']); ?>
<?php endif; ?>

Dev Server Shared Hosting
8 websites powered by drupal 6,8 & 9 - Hosted by Always Data

aiphes’s picture

regions are created in admin/structure/block with this code in template.php:

 if ($blocks = block_get_blocks_by_region('region')) {
      $vars['colonne_c1']['#region'] = 'Colonne_C1';
      $vars['colonne_c2']['#region'] = 'Colonne_C2';
      $vars['colonne_c3']['#region'] = 'Colonne_C3';

  }

and in the .info file :

;Theming de node - inclusion de regions
regions[Colonne_C1] = Colonne C1 - Theming de node
regions[Colonne_C2] = Colonne C2 - Theming de node
regions[Colonne_C3] = Colonne C3 - Theming de node

but content isn't displayed...

Dev Server Shared Hosting
8 websites powered by drupal 6,8 & 9 - Hosted by Always Data

aiphes’s picture

no need to use the code in template.php , but custom regions must to be declared in .info file then in the node.tpl code :

<?php 
if (block_get_blocks_by_region('Colonne_C1')): ?>
<div id="region_col_G1">
    <?php  print render(block_get_blocks_by_region('Colonne_C1')); ?>
</div>
    <?php endif; ?>

then it rocks.. :)

Dev Server Shared Hosting
8 websites powered by drupal 6,8 & 9 - Hosted by Always Data

7huo’s picture

good,Ok.

<?php if (block_get_blocks_by_region('your_region_name')): ?>
    <div id="your_region_name">
        <?php
        $your_region_name = block_get_blocks_by_region('your_region_name');
        print render($your_region_name);
        ?>
    </div>
<?php endif; ?>
off’s picture

Thank you! Its working!

I'm use it with the views php field