0

I am trying to iterate over an array called $module_content in Smarty/php. When a certain condition is fulfilled, I want to assign a value to this.

Dont know why, but my approach does not work.

{php}
    global $module_content;
    $nopic = "./images/nopic.jpg";

    for ($i=0;$i<count($module_content);$i++) {
        if ($module_content [$i]['PRODUCTS_IMAGE'] == '') {
            $module_content [$i]['PRODUCTS_IMAGE'] = $nopic;
        }
        else {
            if (!file_exists ($module_content [$i]['PRODUCTS_IMAGE']) ) 
              $module_content [$i]['PRODUCTS_IMAGE'] = $nopic;
        }
    }

{/php}

The Smarty-Template prompts the var PRODUCTS_IMAGE within an iteration.

{foreach name=aussen item=module_data from=$module_content}
    <img src="{$module_data.PRODUCTS_IMAGE}" alt="" />
{/foreach}

Any help appreciated...

Thank you, in advance.

4

1 回答 1

-1
{foreach $module_content as $module_data}
    {if $module_data.PRODUCTS_IMAGE|file_exist } {*  php function file_exist() must be accessible from Smarty*}
         <img src="{$module_data.PRODUCTS_IMAGE}" alt="" />
    {else}
         <img src="./images/nopic.jpg" alt="" />
    {/if}
{/foreach}
于 2013-09-15T14:20:29.523 回答