Latte {ifset #block} breaking whole layout down

Notice: This thread is very old.
Pavel Janda
Member | 977
+
0
-

Hello,

I found interesting bug in Latte:

  1. Download Nette Sandbox
  2. Edit @layout file to look like this:
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
</head>

<body style="border: 5px solid pink;">
	{ifset sidebar}
		{include content}
		{include sidebar}
	{else}
		{include content}
	{/ifset}
</body>
</html>
  1. Edit Homepage/default.latte to look like this:
{block content}
	Hello
{/block}

What is the result? Pink-bordered site content, good.

  1. Edit Homepage/default.latte to look like this:
{block sidebar}
	Sidebar
{/block}

{block content}
	Hello
{/block}

What is the result? Pink-bordered site content with sidebar, good.

  1. Edit Homepage/default.latte to look like this:
{if TRUE}
	{block sidebar}
		Sidebar
	{/block}
{/if}

{block content}
	Hello
{/block}

What is the result? Pink-bordered site content with sidebar, good.

  1. Edit Homepage/default.latte to look like this:
{if FALSE}
	{block sidebar}
		Sidebar
	{/block}
{/if}

{block content}
	Hello
{/block}

What is the result? “Hello” without even rendering @layout.latte (Can not see any pink border, right?). Whole site is broken.

Last edited by Beton (2015-03-19 16:04)

David Grudl
Nette Core | 8218
+
0
-

Template is not programming language, so block is defined when it exists in template, regardless of its context.

Burák
Member | 2
+
0
-

Well, regardless of whether Latte is or isn't programming language, there is still problem with the condition and not rendering @layoute.latte. And it would be actually nice feature to define blocks depending on condition (e.g. rights of user, depending on time etc).

Pavel Janda
Member | 977
+
0
-

One way or other, that behaviour seems at least questionable.

Template is not programming language and yet we have IF and ELSE in it..

It would be really nice to have an opportunity to put {block} into template depending on some condition. :)

Jan Tvrdík
Nette guru | 2595
+
0
-

@Beton Templates are like classes and blocks are like methods. Most programming languages does not allow you to write sth like:

class HomepageDefaultTemplate
{
    if (FALSE) {
		public function blockSidebar()
		{
			...
		}
    }
}
Pavel Janda
Member | 977
+
0
-

Jan Tvrdík wrote:

@Beton Templates are like classes and blocks are like methods. Most programming languages does not allow you to write sth like:

class HomepageDefaultTemplate
{
    if (FALSE) {
		public function blockSidebar()
		{
			...
		}
    }
}

Well, not by default. But you can make them act like they do. For instance, Nette provides Nette\Object::extensionMethod :)

But here i just quibble.


I thought i just quibble, but when i look deeper into this problem, i see exactly behaviour of extensionMethod. If i define block under particular condition, it depends on the result if it will be stored is some magical static array or not.

And if the block pops up when iterating through that static array, it is the right time to behave like it is defined.