Jump to content

[SOLVED] Smarty help with assigning an array


ballhogjoni

Recommended Posts

I want to assign the array $errormessage[] to output using my smarty foreach loop in my tpl file. I am not getting an error but my screen goes blank. I assume there is an error but I can't figure it out. How can I assign this array to the smarty 'errors' variable so I can use the foreach loop in the tpl file to print the data? Here is my code:

 

PHP File

$errorMessage = array();
$errorMessage[] = "sadlkjf";
$errorMessage[] = "woirdof";
$errorMessage[] = "lkjsdf89ewl";

$smarty->assign('errors', $errorMessage);

 

TPL File

{if $errors}<p style="text-align:center; color:#FF0000;"><ul>{foreach from=$errors key=foo item=message}<li>{$message}</li>{/foreach}</ul></p>{/if}

 

Thanks in advance

Start debugging.

 

{if $errors}
There are errors
{else}
There are no errors
{/if}

 

At least you will have something that will show up! If it doesn't, you have a problem.

From the looks of it, if I remember rightly with Smarty it looks correct. But just try that first.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.