【发布时间】:2014-11-25 10:23:56
【问题描述】:
我有 Joomla v3.x.x 模板覆盖,它使用一些类别过滤器创建同位素布局。
我遇到的问题是,如果在类别的标题中添加一个 & 符号,则该特定类别过滤器将不会显示。
是否有一种方法可以转义或允许与号 (&) 显示而不破坏该特定类别的过滤器?
代码:
<?php
defined('_JEXEC') or die;
JHtml::_('bootstrap.tooltip');
if (count($this->children[$this->category->id]) > 0 && $this->maxLevel != 0) : ?>
<?php foreach ($this->children[$this->category->id] as $id => $child) : ?>
<?php if ($this->params->get('show_empty_categories') || $child->numitems || count($child->getChildren())) : ?>
<?php $data_name = $this->escape($child->title); ?>
<?php $data_option = str_replace(' ', '', $data_name); ?>
<li class="btn btn-primary"><a href="#" data-option-value=".<?php echo $data_option; ?>"><?php echo $this->escape($child->title); ?></a></li>
<?php if (count($child->getChildren()) > 0) : ?>
<?php
$this->children[$child->id] = $child->getChildren();
$this->category = $child;
$this->maxLevel--;
if ($this->maxLevel != 0) :
echo $this->loadTemplate('children');
endif;
$this->category = $child->getParent();
$this->maxLevel++;
?>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif;
这是根据类别标题创建过滤器的特定行:
<li class="btn btn-primary"><a href="#" data-option-value=".<?php echo $data_option; ?>"><?php echo $this->escape($child->title); ?></a></li>
【问题讨论】:
-
类别名称应在进入数据库之前进行清理。您是否检查了类别条目以查看 & 是如何保存在数据库中的。在运行 htmlspecialchars_decode() 或运行要比较的内容后尝试比较类别名称 htmlspecialchars()。
-
谢谢布赖恩 - 有什么办法可以在拉入标题时在上面的代码中做到这一点?
标签: php html escaping joomla3.0