Theme nodeasblock content with a nodeasblock.tpl.php file

toologic - March 1, 2007 - 14:07
Project:Node As Block
Version:6.x-1.x-dev
Component:User interface
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

I'm newbie in drupal and php/

Tell me please? what i do not right?

1. In my theme template.php i write next.

function phptemplate_nodeasblock($node) {
  return _phptemplate_callback('nodeasblock', array('node' => $node));
}

2. Create nodeasblock.tpl.php and put in it next code

<?php

 
// For all other regions, a standard subject.
 
$subject = '<h3 class="title">'.$node->title.'</h3>';
// set our id's & classes. This becomes our target.
?>


<div <?php {
  echo
'id="'.$node->nid.'"';
  echo
' class="block block-',$node->nid,'"';
}
?>
>

  <?php echo $subject ?>

  <div class="content">
    <?php echo $node->teaser ?>
  </div>
  <div class="readon clear"><a href="<?php print '?q=node/'.$node->nid ?>"><?php print t('Read more') ?></a></div>
</div>

And... nothing.

If i delete all may exercises - block display with my node.tpl.php

When and what is error?

#1

mfredrickson - March 1, 2007 - 15:59
Status:active» fixed

Hello toologic,

The problem is that theme_nodeasblock returns an array like:

<?php
 
return array('subject' => l($node->title, 'node/' . $node->nid),
              
'content' => $content);
?>

You're tpl file just returns a string. If you are happy with the block title, you could modify your phptemplate callback function to just return the content portion of the block:

<?php
function phptemplate_nodeasblock($node) {
  return array(
   
'subject' => l($node->title, 'node/' . $node->nid),
   
'content' => _phptemplate_callback('nodeasblock', array('node' => $node)),
  );
}
?>

then just use the .tpl file to control the content of the block (but not it's title).

Good luck! (feel free to reopen this ticket if you need more help)

-Mark

#2

mfredrickson - March 1, 2007 - 16:02
Title:How i can themeing this» Theme nodeasblock content with a nodeasblock.tpl.php file

Renaming as I'm linking to this node in the README file.

#3

toologic - March 1, 2007 - 16:50

So many steps...

1. To prevent output block with block.tpl.php I create new template block-nodeasblock.tpl.php, where only one row inserted

<?php echo $block->content ?>

2. Create (update) my template for nodeasblock output i use a next code in nodeasblock.tpl.php:

<div <?php {
  echo
'id="block-nodeasblock-'.$node->nid.'"';
  echo
' class="block block-nodeasblock-',$node->nid,'"';
}
?>
>

  <h3 class="title"><?php print $node->title ?></h3>

  <div class="content">
    <?php echo $node->teaser ?>
  </div>
  <div class="readon clear"><a href="<?php print '?q=node/'.$node->nid ?>"><?php print t('Read more') ?></a></div>
</div>

Hm... so many steps and snippets for simple access for Node structure.

Result in attached screenshot

AttachmentSize
nodeasblock-shot.jpg 47.91 KB

#4

toologic - March 1, 2007 - 16:57

Any way great thanks for module and help.
Im happy, that it is fast.

Andrew

#5

Anonymous - March 15, 2007 - 17:01
Status:fixed» closed

#6

TheoRichel - March 28, 2008 - 15:19

I would like to remove the 'Sumitted by..' data from my Nodeasblock-block. To get a grip on it I made and modified the following three files (I repeat what I learned above), but I see no changes whatsoever. This is what I did:

1. Added the following code to template.php

function phptemplate_nodeasblock($node) {
  return array(
    'subject' => l($node->title, 'node/' . $node->nid),
    'content' => _phptemplate_callback('nodeasblock', array('node' => $node)),
  );
}

2. Created block-nodeasblock.tpl.php with just this line:
<?php echo $block->content ?>

3. Created nodeasblock.tpl.php witrh the following code:

<div <?php {
  echo
'id="block-nodeasblock-'.$node->nid.'"';
  echo
' class="block block-nodeasblock-',$node->nid,'"';
}
?>
>

  <h3 class="title"><?php print $node->title ?></h3>

  <div class="content">
    <?php echo $node->teaser ?>
  </div>
  <div class="readon clear"><a href="<?php print '../../../../'.$node->nid ?>"><?php print t('Read more') ?></a></div>
</div>

But nothing happens
Firebug even tells me that where in the last piiece of code H3 is ordered I stell get H2

But to repeat: my mean problem is to get rid of the submitted info.

Many thanks

Theo Richel

#7

TheoRichel - March 29, 2008 - 20:17

Well I did soemthing wrong and I found out what: I had PUT one of the files in the wrong directory. Now it functions as intended here, though nog yet as I want. I would like to have the title back and the submitted info away.

#8

wuf31 - March 4, 2009 - 17:28
Version:5.x-1.1» 6.x-1.x-dev
Status:closed» active

Thank you..
But how do you theme it for drupal 6 ??

 
 

Drupal is a registered trademark of Dries Buytaert.