5
Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "./templates/diet-report.tpl" on line 3 "{if is_array($dietcontent) }" - Unexpected " }"' in ...

I did this:

    {if is_array($dietcontent) }
    There is something..
    {else}
    Noope...
    {/if}

When i output {$dietcontent} i get "Array". But on pages where i dont get "Array" I wish to output a text.

Why am i getting error?

I even tried in my controller (this above is in template) :

$data['rapportExists'] = is_array($data['dietcontent']) ? true: false;

and then in my template:

{if $rapportExists == false }
noope
{/if}

Still receives the same error unexpected }

2
  • Can you post the surrounding code? Commented Sep 16, 2011 at 15:45
  • There may be an error in the code above of that line. Please show us the code from line 1. Commented Sep 16, 2011 at 15:47

2 Answers 2

7

You need to remove the space before }. Smarty will not permit whitespace before a closing brace, or after an opening brace. I tested this in some of my own templates and could reproduce your error by placing a space before the closing brace.

{if is_array($dietcontent) }
-------------------------^^^

{if $rapportExists == false }
---------------------------^^^
Sign up to request clarification or add additional context in comments.

3 Comments

@AlienWebguy Those are Smarty 2 docs. I just tested it in Smarty 3 and it fails with the error described.
@AlienWebguy I suspect the two examples on that page which have spaces before the } are typos. Notice none of the other examples have spaces.
@Michael wow, did not know that the space would generate error. It worked without, thanks! accepted
6

You can do it like:

{if $yourArray|is_array}
do something with it
{/if}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.