Missing layout? Make sure you define block for content

I’ve had some troubles with a page that refused to be wrapped in a layout. It turned out I accidentally erased {block #content} in my presenter template. Read on for the background logic explanation.
Here’s my @layout.latte:

<!DOCTYPE …

<html>

<head>

…

</head>

<body>

…

{include #content}

…

</body>

</html>

Note the request to include block #content. I thought that this block would get defined automatically via the inner workings of Nette framework. It turned out that my presenter template needs to define the block specifically.

The surprise that comes when you don’t do so is not that you get a layout without the guts part but vice versa – you get the inner template without the wrapping layout. No error, nice and quiet.

The way I discovered the culprit was that I requested the layout to be added specifically with {layout '../@layout.latte'}.
And bang! I got an InvalidStateException about a missing block.

So, make sure you put {block #content} at the top of your presenter template:

This entry was posted on Thursday, June 16th, 2011 at 12:17 pm and is filed under Nette. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.