沃梦达 / 编程问答 / php问题 / 正文

如何在 Joomla! 中插入 HTML 标签!模块标题?

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

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

问题描述

我想要做的是将一些 HTML 标签添加到我的 Joomla!模块标题.我需要这样的东西

一些<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;?>//发布你的标题

<div><?php echo $module->content;?>//发布你的模块内容

<?php}

然后被Hanny的评论过期了>

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

注意:$wrap_tag 变量存储您想要的标签.你可以把 b, em, u 等放在不同的结果中.

最后一件事是替换显示的标题,所以我替换了这段代码:

title;?></h1>有了这个:

最后的结果是这样的:

function modChrome_myCustomModule($module, &$params, &$attribs){$doc =&JFactory::getDocument();$css = ".otherClass {}";$css .= ".yourClass {}";$wrap_tag = 'b';$html_title = preg_replace("~Ww+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;?>//发布你的标题

<div><?php echo $module->content;?>//发布你的模块内容

<?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("~Ww+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("~Ww+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 标签!模块标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 Joomla! 中插入 HTML 标签!模块标题?

基础教程推荐