How do I group two nodes on the frontpage in a div? I want to have every two articles on the homepage within a div structure.

However, I can't get this done in my node.tpl.php file: if I use the zebra variable to print a  tag before the node when zebra is odd, and a closing  tag after the node when zebra is even then this only works when there are an even number of articles, or otherwise the last div won't be closed.

In code:

&lt;?php if($zebra=='odd'): ?&gt;
     &lt;div class='row'&gt;     
 &lt;?php endif; ?&gt;

 &lt;div id="node-&lt;?php print $node-&gt;nid; ?&gt;" class="[..]"&gt;
 [rest of node here]
 &lt;/div&gt;&lt;!-- /#node-x --&gt;

 &lt;?php if($zebra == 'even'): ?&gt;
     &lt;/div&gt;&lt;!-- /.row --&gt;
 &lt;?php endif; ?&gt;


To make this work, I must be able to know when a node is the last one. But there isn't a variable $last in the node template file, neither is there a $count variable that hold the total number of nodes.

Does anyone has done something similar before?
The node template is not (usually) aware of the context in which it's been called; when you list nodes as teasers each node is themed individually, and has no awareness of the other nodes in the list. 

What you need to do is find out what template/function is responsible for outputting the list of nodes in question and override that in your own theme/module to add the extra divs.

The Theme Developer module might come in quite handy here, it provides an in-page way of isolating which theme functions have been responsible for rendering which areas of the page.