JUST OPEN SOURCE MATTERS!

September 8, 2008

Custom teaser length by View using node.tpl.php

Filed under: drupal, open source — Tags: , , , , — egoleo @ 5:23 am

I have been working on this project, http://www.newsafrican.com which is a news site which focuses on everything african news. This project is been built on the Drupal CMS which is very flexible arguably.

I got into a situation where i have to customise the teaser length by View which happens to be one of the Drupal modules using node.tpl.php.

One way to vary teaser lengths is to check the current View with a modified node.tpl.php modify the output based on this

In this example a teaser of length 75 or 150 will be shown for the Views “frontpage” and “ghana_page” respectively.

I worked on this for Drupal 5 with the help of the good guys in the drupal IRC rooms, my solution is below. But this is a solution for Drupal 6 by friends on the drupal-support channel of IRC.

<div class="node<?php print ($sticky) ? " sticky" : ""; ?>">
<?php if ($page == 0): ?>
<?php else: ?>
<?php print $picture ?>
<em class="info"><?php print $submitted ?></em>
<?php endif; ?>

<?php
global $current_view;
if(
$teaser) {
if(
$current_view->name == ‘frontpage’)
{
?>

<?php foreach ((array)$node->field_news_image as $item) { ?>
<div class=”field-item”><?php print $item[‘view’] ?></div>
<?php } ?>
<h2><a href=”<?php print $node_url ?>” title=”<?php print $title ?>“><?php print $title ?></a></h2>
<?php print $node->content[‘body’][‘#value’];
}

if($current_view->name == ‘ghana_page’)
{
?>
<?php foreach ((array)$node->field_news_image as $item) { ?>
<div class=”field-item”><?php print $item[‘view’] ?></div>
<?php } ?>
<h2><a href=”<?php print $node_url ?>” title=”<?php print $title ?>“><?php print $title ?></a></h2>
<?php print $node->content[‘body’][‘#value’];
}

if($current_view->name == ‘africa_page’)
{
?>
<?php foreach ((array)$node->field_news_image as $item) { ?>
<div class=”field-item”><?php print $item[‘view’] ?></div>
<?php } ?>
<h2><a href=”<?php print $node_url ?>” title=”<?php print $title ?>“><?php print $title ?></a></h2>
<?php print $node->content[‘body’][‘#value’];
}
if(
$current_view->name == ‘business_page’)
{
?>

<?php foreach ((array)$node->field_news_image as $item) { ?>
<div class=”field-item”><?php print $item[‘view’] ?></div>
<?php } ?>
<h2><a href=”<?php print $node_url ?>” title=”<?php print $title ?>“><?php print $title ?></a></h2>
<?php print $node->content[‘body’][‘#value’];
}

if($current_view->name == ‘gh1’ || $current_view->name == ‘gh2’)
{
?>
<?php foreach ((array)$node->field_news_image as $item) { ?>
<div class=”field-item”><?php print $item[‘view’] ?></div>
<?php } ?>
<h2><a href=”<?php print $node_url ?>” title=”<?php print $title ?>“><?php print $title ?></a></h2>
<?php print substr($node->content[‘body’][‘#value’], 0, 90). ‘&nbsp;’;
?>
<a href=”<?php print $node_url ?>” title=”read more”>read more</a><?php
}
} else {
print
$content;
}
?>

July 14, 2008

The server encountered an internal error or misconfiguration

Filed under: drupal, internet — Tags: — egoleo @ 10:54 am

I encountered the following error when I uploaded an existing site to a new server.

The server encountered an internal error or misconfiguration and was unable to complete your request.

The problem was the .htaccess file. I deleted the .htaccess and the web server worked again.

Subsequently, I recreated the file directly on the server using vim and the server still worked, I think therefore the problem was likely to be an issue with DOS carriage returns / line feeds versus what the Linux server expected.

Several tools exist on the web to help create .htaccess files online, but generally any text editor will work. Do be sure to test your site thoroughly after making an adjustments to the .htaccess file.

June 2, 2008

Drupal Links

Filed under: drupal — Tags: — egoleo @ 10:05 am

Drupal is a very powerful content management system (CMS). But it can be very confusing and fustrating to start with and get documentations.
I have been working on some drupal projects for the past 2 weeks. And i have really come a long way getting some documentation links on Drupal. So i have decided not to allow people also go through by parcelling all the documentation links i came across on the web and also got through the IRC.

And i will be updating each time somthing new comes up 🙂

For Drupal Clean URLS
http://drupal.org/node/15365

Flash Video in Drupal 5: A complete multimedia tutorial
http://www.travistidwell.com/flashvideo

Create a free website or blog at WordPress.com.