Jeff-Lewis / smarty-php

Automatically exported from code.google.com/p/smarty-php
0 stars 0 forks source link

{if isset($object)} fails #139

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi all,
I have this template: 
---------------------
{foreach $serviceList as $service} 
  {if isset({$service->src})} 
    ///do smth using  $service->src 
  {/if} 
{/foreach}
---------------------
$serviceList is array of objects, field 'src' is object too.

Smarty compiles condition with isset into php-code: 
---------------------
<?php ob_start();?> 
<?php echo $_smarty_tpl->tpl_vars['service']->value->src;?> 
<?php $_tmp1=ob_get_clean();?><?php if (isset($_tmp1)){?>
---------------------

So it is an error, because php cannot echo an object, because cannot convert it 
to string. 

Why not to generate simply 
<?php if (isset($_smarty_tpl->tpl_vars['service']->value->src)){?>

I am using Smarty 3.1.13 with php 5.3 on Windows 7(WAMP Denwer)

Original issue reported on code.google.com by yourick...@gmail.com on 22 May 2013 at 1:03

GoogleCodeExporter commented 9 years ago
You did use wrong code. It should be

{foreach $serviceList as $service} 
  {if isset($service->src)} 
    ///do smth using  $service->src 
  {/if} 
{/foreach}

No  {...}  inside the isset()

Original comment by Uwe.Tews@googlemail.com on 23 May 2013 at 8:58

GoogleCodeExporter commented 9 years ago
oh sorry for my inattentiveness and thanks for your help

Original comment by yourick...@gmail.com on 24 May 2013 at 4:20