如何在Joomla中插入HTML标签!模块标题? [英] How to insert HTML tags in Joomla! module title?

查看:122
本文介绍了如何在Joomla中插入HTML标签!模块标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是在Joomla中添加一些HTML标记!模块标题.我需要这样的东西

Some <b>Title</b>

但是当我保存!Joomla会修剪标题并删除所有HTML标记.

我已经检查了administrator/com_content,我认为这应该负责插入数据库数据,但是我在那找不到答案.

有人可以帮助我解决这种头痛吗?

解决方案

所以我找到了解决方案.它包含了先前的两个答案,所以我在这里用正确的代码添加了一个新答案.

首先,我要说的是,该解决方案仅适用于固定数量的单词(最后一个,两个等).我只需要拥有最后一个单词,因此我将发布一个示例代码,其中只包含一个单词

首先作为 SMacFadyen ,我需要在我的模板html文件夹中创建一个新的模块结构:/templates/system/html/modules.php文件.

注意:如果您不想将此新模块样式添加到所有模板,而只是在其中一个模板上,则需要将module.php放入模板的html文件夹中.

SMacFadyen 提供的内容如下:

function modChrome_myCustomModule($module, &$params, &$attribs)
{
$doc =& JFactory::getDocument();
$css  = ".otherClass {}";
$css .= ".yourClass {}";

$doc->addStyleDeclaration($css);

?>
    <div>
        <?php if ($module->showtitle != 0) : ?>
            <h1><?php echo $module->title; ?></h1>
    <?php endif; ?> // post your title
    </div>
    <div>
         <?php echo $module->content; ?> // post your module content
    </div>

<?php
}

然后由 Hanny 的注释过期.我添加了一些php代码以匹配标题的最后一个单词并将其存储在新的变量中.代码如下:

$wrap_tag = 'b';
$html_title = preg_replace("~\W\w+\s*$~", '<'.$wrap_tag.'>'.'\\0'.'</'.$wrap_tag.'>', $module->title);

注意:$wrap_tag变量存储所需的标签.您可以将b,em,u等放入不同的结果.

最后一件事是替换显示的标题,所以我替换了以下代码: <h1><?php echo $module->title; ?></h1> 与此: <h1><?php echo $html_title; ?></h1>

最终结果是:

function modChrome_myCustomModule($module, &$params, &$attribs)
{
$doc =& JFactory::getDocument();
$css  = ".otherClass {}";
$css .= ".yourClass {}";

$wrap_tag = 'b';
$html_title = preg_replace("~\W\w+\s*$~", '<'.$wrap_tag.'>'.'\\0'.'</'.$wrap_tag.'>', $module->title);

$doc->addStyleDeclaration($css);

?>
    <div>
        <?php if ($module->showtitle != 0) : ?>
            <h1><?php echo $html_title; ?></h1>
    <?php endif; ?> // post your title
    </div>
    <div>
         <?php echo $module->content; ?> // post your module content
    </div>

<?php
}

感谢大家的帮助.

What I'm trying to do is to add some HTML tags to my Joomla! module titles. I will need something like this

Some <b>Title</b>

but when I save !Joomla trims the titles and remove all HTML tags.

I've check the administrator/com_content, which I think should be responsible for inserting the database data, but I couldn't find the answer there.

Can anyone help me with this headache?

解决方案

So I found the solutions. It includes both of the previous answers, so I'm putting a new one here with the correct code.

First of all I need to say, that this solution works only for a fixed amount of words (last one, two, etc.) I need only to have the last one, so I will post an example code with one word.

First as SMacFadyen sad I needed to create a new module structure in my template html folder: /templates/system/html/modules.php file.

Note: If you don't want to add this new module styling to all templates, but just on one of them you need to put the module.php in your template's html folder.

The provided by SMacFadyen looks like this:

function modChrome_myCustomModule($module, &$params, &$attribs)
{
$doc =& JFactory::getDocument();
$css  = ".otherClass {}";
$css .= ".yourClass {}";

$doc->addStyleDeclaration($css);

?>
    <div>
        <?php if ($module->showtitle != 0) : ?>
            <h1><?php echo $module->title; ?></h1>
    <?php endif; ?> // post your title
    </div>
    <div>
         <?php echo $module->content; ?> // post your module content
    </div>

<?php
}

Then expired by the comments of Hanny I've added some php code to match the last word of the title and to store it in a new varibale.The code looks like this:

$wrap_tag = 'b';
$html_title = preg_replace("~\W\w+\s*$~", '<'.$wrap_tag.'>'.'\\0'.'</'.$wrap_tag.'>', $module->title);

Note: the $wrap_tag variable stores the tag you want. You can put b, em, u and etc. to have different result.

The last thing was to replace the displayed title, so I've replaced this code: <h1><?php echo $module->title; ?></h1> with this one: <h1><?php echo $html_title; ?></h1>

The final result was this:

function modChrome_myCustomModule($module, &$params, &$attribs)
{
$doc =& JFactory::getDocument();
$css  = ".otherClass {}";
$css .= ".yourClass {}";

$wrap_tag = 'b';
$html_title = preg_replace("~\W\w+\s*$~", '<'.$wrap_tag.'>'.'\\0'.'</'.$wrap_tag.'>', $module->title);

$doc->addStyleDeclaration($css);

?>
    <div>
        <?php if ($module->showtitle != 0) : ?>
            <h1><?php echo $html_title; ?></h1>
    <?php endif; ?> // post your title
    </div>
    <div>
         <?php echo $module->content; ?> // post your module content
    </div>

<?php
}

Thanks to everybody for the help.

这篇关于如何在Joomla中插入HTML标签!模块标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆