【问题标题】:Joomla 3 - category link breaking if category title contains an ampersand &Joomla 3 - 如果类别标题包含&符号&
【发布时间】: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


【解决方案1】:

该问题很可能与过滤器选择的呈现有关。尝试更改以下行:

<?php $data_name = $this->escape($child->title); ?>

到:

<?php $data_name = htmlspecialchars($child->title); ?>

然后看看是否能解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    • 2014-02-16
    • 1970-01-01
    • 2016-06-25
    • 2017-06-01
    • 2022-12-10
    • 1970-01-01
    相关资源
    最近更新 更多