在模板中更新smarty中的对象变量的值

时间:2015-07-13 05:38:56

标签: smarty prestashop prestashop-1.6

我正在尝试以简单的方式修改模板,而不是重写底层代码。我意识到通常对象分配不是在模板中完成的,但有可能吗?

我想要这样的事情:

- (UIColor *)colorFromColor:(UIColor *)fromColor toColor:(UIColor *)toColor percent:(float)percent
{
    float dec = percent / 100.f;
    CGFloat fRed, fBlue, fGreen, fAlpha;
    CGFloat tRed, tBlue, tGreen, tAlpha;
    CGFloat red, green, blue, alpha;

    if(CGColorGetNumberOfComponents(fromColor.CGColor) == 2) {
        [fromColor getWhite:&fRed alpha:&fAlpha];
        fGreen = fRed;
        fBlue = fRed;
    }
    else {
        [fromColor getRed:&fRed green:&fGreen blue:&fBlue alpha:&fAlpha];
    }
    if(CGColorGetNumberOfComponents(toColor.CGColor) == 2) {
        [toColor getWhite:&tRed alpha:&tAlpha];
        tGreen = tRed;
        tBlue = tRed;
    }
    else {
        [toColor getRed:&tRed green:&tGreen blue:&tBlue alpha:&tAlpha];
    }

    red = (dec * (tRed - fRed)) + fRed;
    green = (dec * (tGreen - fGreen)) + fGreen;
    blue = (dec * (tBlue - fBlue)) + fBlue;
    alpha = (dec * (tAlpha - fAlpha)) + fAlpha;

    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}

我想阅读对象变量$ product-> available_now,并根据其内容将其更新为其他内容,以便稍后在模板中使用。

我尝试的所有内容都以空白屏幕或其他方式结束(如上面的代码所示)是一个未更改的变量。

仅供参考:这适用于prestashop

2 个答案:

答案 0 :(得分:0)

尝试:

{if $product->available_now == "XXX001"}
    {assign var=product->available_now value="YYY123"}
{/if}

答案 1 :(得分:0)

我必须承认我没有测试过,但它必须是你犯的错误,因为这是为变量赋值的正确方法!