Function theme('node', $node, $teaser, $page) can't detect a preview and therefore often renders it incorrectly. The problem is that !$page is usually interpreted as "the node is part of a listing" in the themes and therefore the previewed page may look, depending on the theme, very different on the actual page.

Perhaps theme() should get somewhat more detailed context info than just $page?

CommentFileSizeAuthor
#2 comment.module_5.patch290 bytesGeary
#1 node.module_5.patch384 bytesGeary
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Geary’s picture

Title: Preview themed as a node list (no way to detect preview) » Patch adds $node->preview flag for themed previews
FileSize
384 bytes

Here is a patch to node.module that adds a $node->preview flag which themes can use to display previews appropriately. This seems like the simplest possible core change to support styled previews.

For more information, screen shots, and a working demo using an updated FriendsLight theme, see:

http://mg.to/2005/03/13/drupal-preview-confusion

and

http://drupal.mg.to/2005/03/13/friendslight-theme-with-styled-preview

I am submitting a similar patch to comment.module.

Geary’s picture

Title: Patch adds $node->preview flag for themed previews » Patch adds $comment->preview flag for themed previews
Component: node.module » comment.module
FileSize
290 bytes

Here is a patch to comment.module that adds a $comment->preview flag which themes can use to display previews appropriately. This seems like the simplest possible core change to support styled previews.

For more information, screen shots, and a working demo using an updated FriendsLight theme, see:

http://mg.to/2005/03/13/drupal-preview-confusion

and

http://drupal.mg.to/2005/03/13/friendslight-theme-with-styled-preview

I am submitting a similar patch to node.module.

Geary’s picture

Title: Patch adds $comment->preview flag for themed previews » Oops, both the patches above are for the CVS version
Component: comment.module » node.module

Oops, one of my patches above says "4.5.2". Both of these patches are actually against the CVS code. Sorry about the mixup. (Other than line numbers, the same patch works for 4.5.2 or CVS.)

Geary’s picture

Title: Oops, both the patches above are for the CVS version » Patches add $node->preview and $comment->preview so themes can style previews

It seems that when I enter a title in one of these comments, it changes the title on the main entry I'm replying to. Since my previous comment left a title that made no sense out of context, I'm adding this comment in the hope of changing the main title so it makes sense again. Sorry about that.

JonBob’s picture

Title: Patches add $node->preview and $comment->preview so themes can style previews » Preview themed as a node list (no way to detect preview)
moshe weitzman’s picture

seems like we'd want a similar flag for a node preview. yours is a comment preview. would be a nice enhancement to this patch.

Geary’s picture

Hi Moshe,

Yes, I did both the node and comment. Just got a little mixed up about how to post the patches. They should both be in this thread, or the 4.5.2 versions are on the page I linked to above.

elonen’s picture

Hmm.. How about changing the $page boolean to a more generic $context[] instead of adding a new flag?

It'd be nice if the themes could also explicitly detect, for example, taxonomy node listing context or a node embedding context. Individual modules could then decide if they wanted to expose themselves to the themes or not and could even do...

$context['foo_module'] = 1 + @$context['foo_module'];
$foo = theme('node', $node, $teaser, $context);

...if they wanted to let the themes detect multiple nested calls.

Geary’s picture

Yes, the more generic $context[] sounds like a winner. My patch is more along the lines of "what is the smallest change to the existing code" rather than "what is the best design". The reason is that I was really looking for something to use right away on my site running 4.5.2, and I didn't want to break anything in the process. :-)

After getting it working on 4.5.2, then I thought of submitting it for 4.6.

But... See Chris and Steven's comments here: http://drupal.org/node/18845

drumm’s picture

Status: Needs review » Closed (duplicate)