2

I'm new in smarty!I have a loop to print a table!but it's make synatc error what's wrong ?

{foreach $messages as $message}
<tr style="{if !$message->read }font-weight:bold;{/if}">
    <td style="width: 3%; background: #EFEFEF" align="center"><input type="checkbox" name="selected[]" class="selected" value="{$account->username}{chr(22)}{$account->email}" /></td>
    <td style="width: 3%;" align="center"  >{$smarty.get.offset+($message@index+1)}</td>
    <td style="width: 20%;" >{$message->from}{if $message->firstname || $message->lastname}<span style="font-size:10px;font-weight:normal;color:#666"> <br />{$message->firstname} {$message->lastname}</span>{/if}</td>
    <td style="width: 46%;" ><a href="{$smarty.server.PHP_SELF}?mod=message&amp;caption=get&amp;id={$message->id}">{$message->subject}</a></td>
    <td style="width: 30%;" >{lib_abstracts::convertTime($message->cDate, '', TRUE, TRUE)}</td>
</tr>
{/foreach}
2
  • What is the syntax error it reports? Commented Jul 17, 2011 at 13:40
  • Syntax Error in template "D:\Apache2\htdocs\portal\admin/../admin/templates/listMessage.tpl" on line 96 " <tr style="{if !$message->read }font-weight:bold;{/if}"> " - Unexpected " }", expected one of: "|" , "}" , "*" , "/" , "%" , "+" , "-" , ""&"" , ISIN , ISDIVBY , ISNOTDIVBY , ISEVEN , ISNOTEVEN , ISEVENBY , ISNOTEVENBY , ISODD , ISNOTODD , ISODDBY , ISNOTODDBY , "==" , "!=" , "(>,gt)" , "(<,lt)" , "(>=,ge)" , "(<=,le)" , "===" , "!==" , "(%,mod)" , "(&&,and)" , "(||,or)" , "xor" Commented Jul 17, 2011 at 13:43

2 Answers 2

3

You have white space in here ->read } remove this and it'll be work

<tr style="{if !$message->read }font-weight:bold;{/if}">
Sign up to request clarification or add additional context in comments.

3 Comments

@user848689: Just asking, didn't want to say you should not accept it. You can accept any answer you love, even if it does not fully answers your question. See: meta.stackexchange.com/questions/5234/…
@hakre: So remove your beautiful comments from my questions!
@Hamid Seyyedi: Your questions?
1

Your foreach syntax is incorrect. You're using PHP style foreach. Smarty's is a bit different. Note: your syntax is valid for Smarty 3. If you're using Smarty 2.x, use:

{foreach from=$messages item=message}
  ....
{/foreach}

Smarty foreach docs

1 Comment

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.