简体   繁体   English

在Smarty PHP中将值分配给数组

[英]assign value to an array in smarty php

I am trying to iterate over an array called $module_content in Smarty/php. 我试图遍历Smarty / php中名为$module_content的数组。 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. Smarty-Template在一次迭代中提示var PRODUCTS_IMAGE。

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

Any help appreciated... 任何帮助表示赞赏...

Thank you, in advance. 先感谢您。

{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}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM