tom boone dot com
Excavating the grey area between pop culture and reality...

The Blog : August 2008

Tuesday, August 26, 2008 - 12:40pm

As reported by numerous users on Drupal.org, adding the Node: Body field to a view displays the entire node (i.e., title, author, body, CCK fields), not just the body field. Given that the display of Node: Body is controlled by node.tpl.php (or node-$type.tpl.php), this limits your ability to manipulate individual fields.

Add/Edit View:

One solution to this problem is disabling Drupal's default Body field for a content type. To do this, delete the "Body field label" value in the content type's Submission Form Settings. Then replace the Body field with a CCK text field. This new field will be available in Views UI and will display only the field's contents.

Edit Content Type:

Often, however, a site is already filled with content that uses the default body field. One workaround for this is to manually edit the site's database, copying the body field values into the new CCK field.

Unfortunately, after disabling the body field in some content types, the default field continues to display in the node edit form, thus requiring a more complex solution.

Using Contemplate to Display the Body Field
While Node: Body displays an entire node, there is a variable in Drupal that refers only to the content of the body field:

$node->content['body']['#value']

A solution suggested by BeatnikDude in a Drupal.org comment is to hijack the content type's teaser using the Content Templates module (aka Contemplate). In the Teaser template, check the box labeled "Affect teaser output" and enter this code into the template's text box:

<?php print $node->content['body']['#value'] ?>

Content Template:

Now when adding fields to a view in Drupal 6, select Node: Teaser.

Drupal 6:

In Drupal 5, select Node: Body and change the Handler to "Teaser."

Drupal 5:

The view will now display only the contents of the body field, allowing you to individually select only those fields you wish to display.

Manually Trimming the Body Field Display in Views
The biggest drawback to hijacking the Teaser template is that you no longer have a trimmed version of your node available. All calls to the teaser now display the untrimmed body field text. However, there is a workaround to create trimmed body text in Views.

Drupal 6:
In Views for Drupal 6 it's possible to create a template file for each individual field. The default field template used by Views (views-view-field.tpl.php) contains a single line of code:

<?php print $output; ?>

In a view titled 'test' containing a teaser field, you can create a separate template file (views-view-field--test--teaser.tpl.php, in this example) that controls the display of the Node: Teaser. To see what file name to use for a field, check the Theme: Information link in the Views UI.

You will first need to define a function for trimming the length of a string. This should be placed into your theme's template.php file or, if you want the function available to all themes, in a custom helper module. For this example, I'm using neat_trim() (via Justin-Cook.com):

<?php
function neat_trim($str, $n, $delim='&hellip;') {
 
$len = strlen($str);
  if (
$len &gt; $n) {
   
preg_match('/(.{' . $n . '}.*?)\b/', $str, $matches);
    return
rtrim($matches[1]) . $delim;
  }
  else {
    return
$str;
  }
}
?>

In the field template file (views-view-field--test--teaser.tpl.php), use that function to trim the teaser's length:

<?php
$string
= neat_trim($output, 100);
print
$string;
?>

The field display will now be limited to 100 characters.

Drupal 5:
In Drupal 5, define a string trimming function in the same manner as in Drupal 6.

Unfortunately, in Drupal 5 you're limited to creating template files that cover an entire view, not individual fields, but you can still tweak a single field within this template.

To generate template code, use the Views Theme Wizard module (included with Views). This provides three code snippets: one to add to template.php, one to paste into a new view template file (views-list-test.tpl.php in this example -- the theme wizard will tell you what to name it), and one to create a stylesheet for your view.

In your new view template file look for:

<div class="view-field view-data-body">
  <?php print $body ?>
</div>

Then apply your trim function on $body:

<?php
$string
= neat_trim($body, 100);
?>

<div class="view-field view-data-body">
  <?php print $string ?>
</div>

(8)
Friday, August 22, 2008 - 8:29pm

California Republic

California
(3)
Wednesday, August 20, 2008 - 1:58pm

I've noticed a lot of my friends on Twitter locking their updates in recent days. From what I gather, the rationale behind these changes are logical and predictable: a desire for more privacy. Privacy from spam followers. Privacy from search engines. Privacy from co-workers/supervisors. Et cetera. Et cetera.

I'm currently weighing this question myself, but I'm sticking with the open model, at least for now. Why? Well, for one my supervisor is already following me on Twitter, so even if I locked updates, he'd still see everything. I have no desire to lock him out anyhow, as he and I have used Twitter on numerous occasions to communicate about work issues. It's actually been *gasp!* PRODUCTIVE. Of course, because my supervisor is following me on Twitter, I already know not to say things I wouldn't want the higher ups to see. Maybe that feels limiting at times, but it probably prevents me from saying things that would be unprofessional no matter who my audience was. Though in all fairness, even knowing my boss is watching hasn't prevented me from pushing the boundaries of appropriateness from time to time (*cough" RedDot *cough*).

As for spam followers, won't I still receive requests from those same bots? Won't I still have to go decline those requests? (I don't know the answer to that question. Could someone with locked updates answer that for me?) If so, that reminds me a lot of my current periodic maintenance of blocking the bots who are already following me.

In general, I'm still on board the open updates wagon because it helps me connect with new people. When I receive an email notification that I have a new follower, I always go to their profile to see who they are and if I want to follow them. If their updates are locked, and I have no way of knowing who they are, I'm not going to follow them. And so I assume the same is true for my updates. If people see me tweeting about open source software or libraries or movies, that might be a reason for them to follow me. And I'd like to encourage that kind of interaction. At least for now.

The recent trend of locked updates reminds of what happened on MySpace a year or two ago. At first, we all had public profiles, and every last dirty detail was out there for the world to see. Slowly, as more and more people realized there might be consequences to this sort of openness, people started to lock their profiles, making them visible only to friends. And then eventually most of us moved to Facebook anyway, a system that hides most of our information from the outside world by default (not that FB isn't without its own unique privacy problems).

Perhaps Twitter will eventually evolve into a similarly closed network. But if that happens, I hope Twitter adopts a setting similar to what Facebook has. That is, when someone with locked updates begins following my updates, I should have a window of time in which I can view their updates, too. That way I can determine whether or not I want to reciprocate and follow them. Otherwise I often have no information to go on.

(5)
Sunday, August 17, 2008 - 7:34pm

Yesterday's Boston Globe featured a column by Alex Beam expressing his reservations about Twitter:

You have heard about Twitter. Maybe. It's something other people do, mainly younger people. You subscribe to the service, then you can post little messages on people's cellphones, or on their instant message accounts. About nothing.

[...]

The perfect twitter is a lapidary techno-haiku: I send these pointless little messages, gobbling up Internet bandwidth for no reason. Because I am a twit . . . er.

In honor of Beam's article, I've created a blog badge for those of us who are the targets of his derision. Feel free to use the badge however you like. I have one in the sidebar of my page that links to my Twitter profile.

Many of you know I post to Twitter several times a day on average, but it took me several months of using (and more often NOT using) the site before I started to get anything out of it. Once I found a substantial number of people to follow (many of whom are fellow law librarians) and who followed me in return, however, the conversation took off. I am now in constant contact with librarians all over the country every single day.

I posted my own favorite Twitter experience as part of a comment to a post at Out of the Jungle about Beam's column:

A few weeks ago a librarian in Chicago Twittered that she was interested in an AALL session on empirical research. I replied to her -- via Twitter -- that I was also interested in this topic because I was working with such materials at work. Two days later, a librarian in LA who isn't even on Twitter asked me about my empirical research after she had a phone conversation the Chicago librarian. Minus Twitter, I wouldn't have made either of these valuable professional connections.

So I will continue to send pointless little messages.

(0)
Sunday, August 3, 2008 - 10:07pm

Just finished watching Enron: The Smartest Guys in the Room, and I'm extremely disappointed. Filmaker Alex Gibney completely missed the mark in this adaptation of Peter Elkind and Bethany McLean's book of the same name. What should be a complex dissection of CFO Andy Fastow's financial shenanigans, an unforgiving examination of Jeff Skilling and Ken Lay's dealmaking corporate environment, and a scathing indictment of Wall Street in the bull market of the 90s is instead little more than a dumbed down story of the big company that fell down and went boom.

Gibney inexplicably spends 30 minutes, well over a quarter of the movie, discussing Enron's role in the California electricity crisis of 2000-01. Nevermind that Enron, as Elkind and McLean clearly explain in the book, 1) never broke the letter of the law with their California transactions, 2) was just one of many companies engaged in profiteering during the crisis, and 3) actually made money from these transactions (whereas Enron went bankrupt because it ultimately lost money from other transactions -- most of which are ignored in the film). As if wasting our time with an irrelevant tangent isn't enough, Gibney concludes this segment of the film by implying that Enron is to blame for Arnold Schwarzenegger becoming governor of California.

The film also tries to make much of alleged links between Enron and the Bush family, but as any reader of the book knows that while Ken Lay did little to deny a close tie to each President Bush, in reality his ties were tenuous at best, and in the case of the younger Bush virtually nonexistent.

Oh, and Arthur Andersen is barely mentioned.

The heart of Enron's misconduct was the creation of several partnerships by Fastow designed both to keep Enron's losses off the books and to make millions of dollars for Fastow and his cronies, yet Gibney devotes only about 10 minutes to these schemes. Most of those 10 minutes are consumed by Fastow's own conflict of interest and provide little information on what the partnerships were or why they were illegal. While it's true that descriptions of these special purpose entities are hard to follow (I suffered a lot of headaches while reading about them), their inexplicability was one of the reasons they succeed for so long -- because Wall Street analysts couldn't make enough sense of them to see the frightenting truth.

All in all, it seems Gibney simply wanted to make a movie everybody could watch and understand without actually dealing with the details. To accomplish this he played up the human (Lay and Skilling) and emotional (California and lost pensions) elements while downplaying the financial (everything that mattered). What this leaves is an oversimplified version of events that is nearly as deceptive as the one told by Enron itself.

Read the book.

(0)
Syndicate content