0

I am using Display Suite to create two new view modes within my D7 instance. They are:

  • Wide
  • Square

I can get them created and and added to the content creation form BUT I'd like to create a preview image for those two view modes to give the end user some type of visual of what they're selecting.

I see there are layout previews when a layout is chosen but not for view modes. Do i just need to create a new layout template for the view mode? if so where should these files live?

First time using this module.

1

View modes are a Drupal concept, and layouts (in this context) are specific to Display Suite. Selecting a preview image for a view mode (if it can be done) has got nothing to do with Display Suite. The preview images that Display Suite show is specific to the layouts that it offers.

In Display Suite, you can define your own custom layouts, and there are a few ways of doing so. Some modules add layouts as well. To investigate how a module does that, download Display Suite Bootstrap Layouts and have a look at the files. You will see the module file, wherein the layout is declared as such:

$layouts['bootstrap_12'] = array(
    'label' => t('Bootstrap One Column: 12'),
    'path' => $onecol . '/bootstrap_12',
    'regions' => array(
      'central' => t('Content'),
    ),
    'form' => TRUE,
    'image' => TRUE, // this tells it that there is an image for the layout
  );

Note the key 'image' is set to TRUE to indicate the presence of an layout image, which you will find in the sub folders.

The template files that goes with this declaration is found in layouts -> onecol -> bootstrap_12 -> bootstrap-12.tpl.php and looks like this:

<<?php print $layout_wrapper; print $layout_attributes; ?> class="<?php print $classes; ?>">
  <?php if (isset($title_suffix['contextual_links'])): ?>
    <?php print render($title_suffix['contextual_links']); ?>
  <?php endif; ?>
  <div class="row">
    <<?php print $central_wrapper; ?> class="col-sm-12 <?php print $central_classes; ?>">
      <?php print $central; ?>
    </<?php print $central_wrapper; ?>>
  </div>
</<?php print $layout_wrapper ?>>


<!-- Needed to activate display suite support on forms -->
<?php if (!empty($drupal_render_children)): ?>
  <?php print $drupal_render_children ?>
<?php endif; ?>

Here you can see how the central region defined in the module file is rendered within the template using a naming convention.

You can add layouts to this module directly if you want by following the convention above. But better would be to define them in your own theme folder so that you don't wipe out your changes during an upgrade.

You can do that manually or using drush, and the layout files will live in a subfolder 'ds_layouts' within your theme folder. The process is fully described in Adding custom layouts to your theme. It is really very easy to do, and well worth the effort.

So to come back to your question, in order to associate a preview image with a view mode, you could declare a new layout with a peview image that is used only for a specific view mode, thereby creating a one-to-one relationship between them.

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.