Echo a variable only if it exists

Notice: This thread is very old.
netteman
Member | 125
+
0
-

Hello

I want to echo a variable in my template only if the variable exists.
I found out that this code works

public function renderDefault()
{
    $this->template->varrr = "something";
}//end mtd

Latte

{block content}
	{if @$var}
    	{$var}
	{/if}
{/block}

I had to add @ to the condition because I got “Undefined variable: var” error otherwise.

Is it OK to avoid this error by using @ or is there something else I should use in latte/templates?

Thanks

Last edited by netteman (2016-05-01 11:30)

CZechBoY
Member | 3608
+
0
-

You should use isset instead of suppressing error.

Majkl578
Moderator | 1364
+
+2
-
netteman
Member | 125
+
0
-

Thanks guys :)