问题描述
想知道是否有人将magento布局XML中的or语句用于自定义模块吗?我意识到我可以检查模块控制器中的值或自身块,但这似乎是逻辑存在的逻辑场所.
Wondering if anyone has used the or statements in magento's layout XML for a custom module? I realise that I could check the values in the module controller or block itself, but it seems like a logical place for the logic to live.
Mage_Core在catalog.xml
中使用它们来测试javascript. <!--<params/><if/><condition>can_load_calendar_js</condition>-->
Mage_Core uses them in catalog.xml
to test for javascript. <!--<params/><if/><condition>can_load_calendar_js</condition>-->
谢谢,京东
推荐答案
我会回避使用它们.您会注意到,它们在默认的分布式社区版本中已被注释掉,这可能意味着核心团队正在逐渐放弃使用它们.
I'd shy away from using those. You'll notice they're commented out in the default distributed community edition, which probably means the core team is moving away from using them.
如果您对它们的功能感兴趣,那么它们就是参数,严格来说,它们是page/head
块的addItem
方法的一部分.
If you're interested in what they do, they're paramaters that are strictly a part of the page/head
block's addItem
method.
File: code/core/Mage/Page/Block/Html/Head.php
public function addItem($type, $name, $params=null, $if=null, $cond=null)
{
if ($type==='skin_css' && empty($params)) {
$params = 'media="all"';
}
$this->_data['items'][$type.'/'.$name] = array(
'type' => $type,
'name' => $name,
'params' => $params,
'if' => $if,
'cond' => $cond,
);
return $this;
}
添加项目方法存储这些条件,然后在getCssJsHtml
方法中稍后将其用于跳过添加项目.
The add item method stores these conditions, and then they're used later in the getCssJsHtml
method to skip adding an item.
public function getCssJsHtml()
{
// separate items by types
$lines = array();
foreach ($this->_data['items'] as $item) {
if (!is_null($item['cond']) && !$this->getData($item['cond']) || !isset($item['name'])) {
continue;
}
我的猜测是,这是他们在模板系统中添加元编程的早期尝试,最终使目标用户的头上大吃一惊.
My guess is they were an early attempt to add meta-programming to the template system, which ended up going over the head of its intended users.
这篇关于在magento布局xml中使用条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!