【问题标题】:smarty fetch string replacesmarty 获取字符串替换
【发布时间】:2013-03-20 00:48:48
【问题描述】:

当使用 $smarty->fetch 时,它会将模板拉入一个变量中。有没有办法对该变量进行预解析的字符串操作?

例子:

PHP:

$variable = $smarty->fetch('template.tpl');
$variable = str_replace("{include file='../another_dir", "{include file='", $variable);

模板.tpl

{include file='incl.tpl'}

理想的结果是让模板变成:

{include file='../another_dir/incl.tpl'}

【问题讨论】:

    标签: php smarty


    【解决方案1】:

    您必须先编辑模板。然后就可以使用fetch了。

    类似这样的:

    $template = file_get_contents('template.tpl');
    $template = str_replace("{include file='../another_dir", "{include file='", $template);
    $variable = $smarty->fetch('string:' . $template);
    

    聪明的String Template Resources.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-20
      • 2020-04-05
      • 1970-01-01
      • 2022-08-17
      • 1970-01-01
      • 2023-01-20
      • 1970-01-01
      • 2018-06-26
      相关资源
      最近更新 更多