简体   繁体   English

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

[英]How to insert HTML tags in Joomla! module title?

What I'm trying to do is to add some HTML tags to my Joomla! 我要做的是为我的Joomla添加一些HTML标签! 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. 但是当我保存!Joomla修剪标题并删除所有HTML标签。

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. 我检查了管理员/ com_content,我认为应该负责插入数据库数据,但我找不到答案。

Can anyone help me with this headache? 任何人都可以帮我解决这个问题吗?

Check out ../templates/system/html/modules.php 查看../templates/system/html/modules.php

You can style your module structure in HTML. 您可以在HTML中设置模块结构的样式。

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 call your styled module in index.php: 然后在index.php中调用样式化模块:

  <jdoc:include type="modules" name="right" style="myCustomModule"  />

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. 首先,作为SMacFadyen,我需要在我的模板html文件夹中创建一个新的模块结构:/templates/system/html/modules.php文件。

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. 注意:如果您不想将这个新模块样式添加到所有模板中,而只是在其中一个模板上,则需要将module.php放在模板的html文件夹中。

The provided by SMacFadyen looks like this: 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
}

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: 然后由Hanny的评论过期我添加了一些PHP代码来匹配标题的最后一个单词并将其存储在一个新的varibale中。代码如下所示:

$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. 注意: $wrap_tag变量存储您想要的标记。 You can put b, em, u and etc. to have different result. 你可以把b,em,u等等有不同的结果。

The last thing was to replace the displayed title, so I've replaced this code: <h1><?php echo $module->title; ?></h1> 最后一件事是替换显示的标题,所以我已经替换了这段代码: <h1><?php echo $module->title; ?></h1> <h1><?php echo $module->title; ?></h1> with this one: <h1><?php echo $html_title; ?></h1> <h1><?php echo $module->title; ?></h1>这一个: <h1><?php echo $html_title; ?></h1> <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. 感谢大家的帮助。

The Gantry framework can help you accomplish what you want (1st word styled one way, 2nd word styled another) - but it's a lot of overhead just accomplish that one task you're looking for. 龙门架可以帮助你完成你想要的东西(第一个单词是单向的,第二个单词是另一个单词) - 但是要完成你正在寻找的一个任务需要花费大量的开销。 Ultimately you'll have to create a template override for your template, and then do some creative editing with php in order to get it to display that way. 最终你必须为你的模板创建一个模板覆盖,然后用php做一些创意编辑,以便让它以这种方式显示。

There's no quick and easy way to get that done. 没有快速简便的方法来完成这项工作。 You'll have to do some php coding on the backend and edit the template (use an override so you don't hack core files). 你必须在后端做一些PHP编码并编辑模板(使用覆盖,这样你就不会破解核心文件)。 Ultimately you'll probably have to code the php to pull apart the title, and apply formatting to each pulled apart word (or string of words as the case may be) using CSS. 最终你可能需要编写PHP代码来拆分标题,并使用CSS将格式应用于每个拉开的单词(或字符串,视情况而定)。

Hope that helps. 希望有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM