In node.tpl.php, the container div usually starts with

<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">

However, when rendering the default preview for a node, the node template gets called twice, which is good, but also has the effect of putting the element #node-nid twice in the DOM, thus breaking it. This is what it should look like to prevent this:

<div id="node-<?php print $node->nid; ?><?php if ($teaser) { print '-teaser'; } ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">

Since the default node.tpl.php already gets overwritten by usually every theme, this modification would need to be applied to all of them, every node.tpl.php file out there... It's not huge problem, but in the case of the Image placement module which needs to select fields inside the teaser and full node's preview separately, this DOM bug could really get in the way. Some extra "clear" divs would also help make themes more solid.

Comments

geerlingguy’s picture

Just fyi, the Drupal 7 way is now:

<div id="node-<?php print $node->nid; ?>" class="<?php print $classes ?> clearfix">

As JohnAlbin mentioned in IRC, we could change it to:
<div <?php if ($id): ?>id="<?php print $id; ?>"<?php endif; ?> class="<?php print $classes; ?>">

...but that's kinda ugly.

dr_fail suggested:
<?php print $id ? 'id=". $id ."' : ''; ?>

...which would ensure that the ID is only printed once. Still kinda messy-looking, but might just work.

[Edit: Just thinking out loud... We could take one of the above snippets, put it as a theme snippet in drupal.org's theming docs (for those who need this functionality), and remove the node id printing completely from core's node.tpl.php files ;-)]

Damien Tournoud’s picture