1

I've been using Display Suite for Drupal 7 (with Bamboo theme,) and I'm trying to build a layout template that contains 5 rows, so I can place the appropriate fields into each row, making all content nice and tidy.

I've followed the instructions here, but I'm doing something wrong: https://www.drupal.org/node/1098068

I'm guessing it has to do with the PHP code, because I'm getting errors involving my wrappers. Here is the PHP code for the tpl.php file:

<?php

/**
 * @file
 * Display Suite Bamboo custom template.
 */
?>
<<?php print $layout_wrapper; print $layout_attributes; ?> class="ds-bamboo <?php print $classes;?> clearfix">

  <?php if (isset($title_suffix['contextual_links'])): ?>
  <?php print render($title_suffix['contextual_links']); ?>
  <?php endif; ?>

  <<?php print $first_wrapper ?> class="introduction<?php print $first_classes; ?>">
    <?php print $first; ?>
  </<?php print $first_wrapper ?>>

  <<?php print $second_wrapper ?> class="entry1-group<?php print $second_classes; ?>">
    <?php print $second; ?>
  </<?php print $second_wrapper ?>>

  <<?php print $third_wrapper ?> class="entry2-group<?php print $third_classes; ?>">
    <?php print $third; ?>
  </<?php print $third_wrapper ?>>

<<?php print $fourth_wrapper ?> class="entry3-group<?php print $third_classes; ?>">
    <?php print $fourth; ?>
  </<?php print $fourth_wrapper ?>>

  <<?php print $footer_wrapper ?> class="group-footer<?php print $footer_classes; ?>">
    <?php print $footer; ?>
  </<?php print $footer_wrapper ?>>

</<?php print $layout_wrapper ?>>

<?php if (!empty($drupal_render_children)): ?>
  <?php print $drupal_render_children ?>
<?php endif; ?>

I think it is very possible I am also writing my .inc file incorrectly. Here is that code as well:

<?php
function ds_ds_bamboo () {
  return array(
    'label' => t('Bamboo DS'),
    'regions' => array(

        'introduction' => t('Introduction'),
    'entry1-group' => t('Entry 1'),
    'entry2-group' => t('Entry 2'),
    'entry3-group' => t('Entry 3'),
    'group-footer' => t('Footer'),
          ),
    // Add this line if there is a default css file.
    'css' => TRUE,
      );
}

I would be very appreciative if someone can set me in the right direction. Thank you!

  • On further reflection, I think my problem is that I need to define new regions, which I haven't done. In one attempt to make this work, I tried defining all rows as Headers --- which failed, I think, because Header is a specific region which can't be duplicated. So, I think I've answered my own question. However, I would really appreciate advice on how to accomplish my goal of creating 5 row type regions so that all fields can be tidily shipped in. Thanks! – Red May 11 '15 at 22:08
1

I have managed to solve this problem, and I'm posting my own answer here in hopes that it will help someone else struggling with this.

First, when creating a Display Suite Custom Layout, follow the directions here: [https://www.drupal.org/node/1098068][1]

Then, if you are defining custom regions like I am, the trick is to create custom regions in your Drupal theme. To do this, go to sites/all/themes and enter the folder containing your theme. Then find your theme's .info file.

This should be where the regions in your theme are stored and created. To set up the regions that will work with the php code listed above, enter:

your_region_name = [name_of_custom_region]

I created 7 regions this way. For example, my first region is named:

introduction = [introduction]

This may be slightly different given how your theme is set to define regions, but this is what worked for me. I entered my new regions after the pre-existing Content region defined in the theme. (I have no idea if that makes a difference, but that is what worked for me.)

After you have defined the regions, insert and alter the php code from the question above in your Display Suite tpl.php file. (The link in the first step shows you how to define this file.)

You will then change some of the php code to reflect your custom regions. For example, if you defined your first region as "introduction" the code should look like this:

    <<?php print $introduction_wrapper ?> class="introduction<?php print $introduction_classes; ?>">
    <?php print $introduction; ?>
  </<?php print $introduction_wrapper ?>>

You will then need to alter the code each time, entering the next region name that you defined in the .info file in order.

Lastly, you will need to update your Display Suite custom layout .inc file. I did this by defining each newly created custom region that I wanted to show up on the custom layout within Drupal. As an example, my code looked like this in the end:

    <?php
function ds_ds_bamboo () {
  return array(
    'label' => t('Bamboo DS'),
    'regions' => array(

    'articletitle' => t('Article Title'),
        'titleimage' => t('Title Image'),
    'introduction' => t('Introduction'),
    'entry1' => t('Entry 1'),
    'entry2' => t('Entry 2'),
    'entry3' => t('Entry 3'),
    'author' => t('Author Bio'),
          ),
    // Add this line if there is a default css file.
    'css' => TRUE,
      );
}

Doing this will create row-like regions that will allow you to neatly group Drupal fields together, giving you a template for future content.

As an example, my "entry1" region contains an image field, text field, another optional image field and text field, as well as a video embed field. Due to the structure of the code and Display Suite's field management, all of the fields and their content are kept nice and tidy within the custom region.

I hope this helps if you're struggling with defining custom layouts in Display Suite!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.