After 2 days of searching and testing modules for our website, today I stumbled upon this awesome module that does exactly what I'm looking for: give freedom to the content editor to MANUALLY specify which and where pieces of content will display in a 3-column layout of the homepage.

However I'm having a hard time trying to Add or Modify the rendering mode for articles output. What I'm trying to achieve is to simply render only 2 elements from the node:
Node Image
Node Summary/Trimmed text (which will link to the original node).

My very limited php skills aren't helping me much, so any help will be greatly appreciated.

Regards

CommentFileSizeAuthor
#1 sketch.png7.5 KBTunox
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Tunox’s picture

FileSize
7.5 KB

Little progress by digging a little further using as a clue the if statement example given in this module description.
By adding to node.tpl.php :

    if (isset($node->nodesinblock)) {
    $user_picture = '';
    $display_submitted = '';
    }
  

I disabled the display for the pesky user profile picture, and the submit date, but having a tough time finding where to trim the body text and how to change the order of the fields from:

Title
|
Node image
|
Text

to:

Node image
|
Title
|
Text

Basically trying to achieve this:

sketch

Any tips?

Tunox’s picture

Some more progress. We get so lost on searching for tiny details that basic Drupal idiosyncrasies get out of our brain. It was the case with View Mode which is a Drupal thing and responsible for handling the size of the trimmed text I wanted to achieve. On a side note maybe in the project page a link towards what View modes are and how you can add/modify them can be a helpful reminder to future users. For example:
Drupal 7 custom node view modes
Adding View Modes with Entity View Modes module

So I'm almost near to the goal of achieving the desired output except for the node Title that I want it below the image. Since in Drupal we can't rearrange the order of body fields natively, I have to modify node.tpl.php and arrange the markup for $title and $content variables. The issue with this scenario is that it will affect also the full node view which I don't want. To avoid it I have to properly implement

// node.tpl.php
if (isset($node->nodesinblock)) {
  // Theming for node in block
}
else {
  // Normal theming
}

Although a simple if else statement this goes beyond my skills set for now, so some code help to properly integrate the $node->nodesinblock exception will be really useful.

node.tpl.php as it is now

<article class="node-<?php print $node->nid; ?> <?php print $classes; ?> clearfix"<?php print $attributes; ?>>

  <?php 
    if (isset($node->nodesinblock)) {
    $user_picture = '';
    $display_submitted = '';
    }
  ?>

  <?php if ($title_prefix || $title_suffix || $display_submitted || $unpublished || !$page && $title): ?>
    <header>
      <?php print render($title_prefix); ?>
      <?php if (!$page && $title): ?>
        <h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2>
      <?php endif; ?>
      <?php print render($title_suffix); ?>

      <?php if ($display_submitted): ?>
        <p class="submitted">
          <?php print $user_picture; ?>
          <?php print $submitted; ?>
        </p>
      <?php endif; ?>

      <?php if ($unpublished): ?>
        <p class="unpublished"><?php print t('Unpublished'); ?></p>
      <?php endif; ?>
    </header>
  <?php endif; ?>

  <?php
    // We hide the comments and links now so that we can render them later.
    hide($content['comments']);
    hide($content['links']);
    print render($content);
  ?>

  <?php print render($content['links']); ?>

  <?php print render($content['comments']); ?>

</article><!-- /.node -->
Tunox’s picture

ok I hacked my way to achieve the desired output. Here are the steps in case any Nodes In Block future user wants to achieve the same output as in the image in #2

1. In the theme's template.php file add :

function cbtheme_preprocess_node ( &$vars ) {
    if ($vars["is_front"]) {
        $vars["theme_hook_suggestions"][] = "node__front";
    }
}

2. Make a copy of your theme's node.tpl.php and rename it in node--front.tpl.php or if your theme doesn't have any fetch the one from /modules/node folder.
Basically this will allow you to modify the output on the nodes of your homepage independently from your regular full node view. In my case I took out everything except for the title and content variables.

3. In #2 I still had issues with getting the node title between the image and the text. That is because by default $content renders everything there is displayed in the View Mode of the concerned content type (admin/structure/types/manage/article/display/teaser). To separate image from content body (or any other field for that matter) I rendered them separately like this:

print render($content['field_image']);

and

print render($content['body']);

I place the title variable(s) between the two and all is good :)

Obviously you can achieve all of this with Views, but in my case that wasn't an option as the grid output of the views didn't give to the content editor the freedom on manually ordering the node teaser.

For the Drupal pros out there all of this is natural like breathing air, for the rest of us designers and site builders installing a module and learn how it bend it it is critical so one of these days I'll take the time and do a screencast about Nodes in Block.

Tunox’s picture

Status: Active » Closed (fixed)

closed