我正在运行Expression Engine 2.3.0并使用频道图像添加。
该网站的一部分非常复杂,我通过插件而不是使用EE的模板逻辑来实现。我基本上得到的是CodeIgniter控制器和使用我指定的EE模板标签在站点上调用的视图。
我想使用频道图像来使我在视图中显示的频道数据看起来更好一些。问题是...频道图像功能似乎不允许我将其称为PHP。因为EE模板参数。
所以,我决定尝试通过解析器运行模板块。但我没有得到结果。有任何想法吗?或者可能是直接调用函数的解决方法?
<?php $this->EE =& get_instance();
$img_tpl = '{exp:channel_images:images entry_id="'. $item['id'] .'" cover_only="yes"}
<div style="float:left; display:inline; width:125px;">
<a href="{image:url:large}" title="{image:title}"><img src="{image:url:small}" alt="{image:title}" /></a>
<p>{image:description}</p>
</div>
{/exp:channel_images:images}';
$opts = array('');
$img = $this->EE->output->set_output($this->EE->TMPL->parse_variables($this->EE->TMPL->parse_globals($img_tpl), array($opts)));
?>
你在这里度过一段难忘的时光。 EE的前端解析的任何部分都不会被认为是从EE外部调用的。
parse_variables()
和parse_globals()
不解析完整的EE标签对(只有个别变量),这就是为什么你没有得到任何结果。
我真的建议使用EE模板。
https://expressionengine.stackexchange.com/questions/1347
我一直在重新审视这个答案,并希望在ExpressionEngine 3中添加我如何解决它。
// load my own instance of TMPL as myTMPL
ee()->load->library("template", null, "myTMPL");
// get template as a string, and variables as name => value pairs
$template = ee()->myTMPL->fetch_template("mygroup", "mytemplate", false);
$variables = array("name" => "Mr. John Q. Public");
// render the template
$html = ee()->myTMPL->parse_variables($template, array($variables)); // merges variables
ee()->myTMPL->parse($html); // handles conditionals (doesn't seem to run plugins)
$html = ee()->myTMPL->parse_globals(ee()->myTMPL->final_template); // returns output