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?

CommentFileSizeAuthor
#3 nodeasblock-shot.jpg47.91 KBtoologic
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mfredrickson’s picture

Status: Active » Fixed

Hello toologic,

The problem is that theme_nodeasblock returns an array like:

  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:

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

mfredrickson’s picture

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.

toologic’s picture

FileSize
47.91 KB

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

toologic’s picture

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

Andrew

Anonymous’s picture

Status: Fixed » Closed (fixed)
TheoRichel’s picture

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

TheoRichel’s picture

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.

wuf31’s picture

Version: 5.x-1.1 » 6.x-1.x-dev
Status: Closed (fixed) » Active

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

netsensei’s picture

You could override this function in your template.php file

/**
 * Process variables for nodeasblock.tpl.php.
 *
 * The $variables array contains the following arguments:
 * - $node
 *
 * @see nodeasblock.tpl.php
 */
function template_preprocess_nodeasblock(&$variables) {
  $node = $variables['node'];
  // If the user has permissions to edit the node, then add a link.
  if (node_access('update', $node)) {
    $variables['edit_link'] =  l('['. t('edit') .']', 'node/'. $node->nid .'/edit', array("title" => t("Edit")));
  }
  $variables['content'] = $variables['node']->body;
}

There's also a hook theme('nodeasblock', $node); but you have to implement it yourself in your template.php (register with hook_theme and such!)