如何在组件中显示 Joomla 模块?

发布于 2024-09-30 03:15:00 字数 314 浏览 1 评论 0 原文

我有一个包含多个游戏类别的组件,我想根据类别显示不同的横幅。我需要可自定义横幅(和链接),因此这不仅仅是显示 categoryX.jpg 或其他内容。

我在另一个问题上看到了这个 Joomla 帮助页面,但它似乎只显示模块类型,而不显示一个特定的模块。我想使用各种 mod_custom 模块并显示适合该类别的模块(如果需要,我可以存储每个模块的 ID)。

有什么想法吗?

I have a component with several categories of games and I want to display a different banner depending on the category. I need the banner (and link) to be customizable so it's not simply a case of showing categoryX.jpg or whatever.

I saw this Joomla help page on another question, but it only seems to display a module type, not one specific module. I'd like to use various mod_custom modules and display the one appropriate to the category (I can store each module's ID if necessary).

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

情话墙 2024-10-07 03:15:00

这可以通过两步过程完成:

  1. 使用“将模块加载到文章”插件中,以允许您使用如下插件调用来访问模块:

    {module [*mod_id*]} // 其中 *mod_id* 是模块 ID

  2. 现在您可以调用插件将模块放置在任何位置,现在您需要转到您想要添加模块的组件的视图代码并添加以下代码:

    echo JHTML::_('content.prepare', '{module [*mod_id*]}');

请参阅此链接 - http://www.alltogetherasawhole。 org/group/developers/forum/topics/running-joomla-content-plugins - 关于第 2 点。我试图做同样的事情,但发现它不起作用,原因是您可以在上面的页面链接中找到一条评论:

“我注意到某些插件实际上期望 option=com_content 以便它们正确处理 onPrepareContent,因此您实际上可能想通过调用 JRequet::setVar 并恢复正确的值来“愚弄”它们触发后。”

This can be done in a 2 step process:

  1. Use the "Load module into article" plugin to allow yourself to access the module using a plugin call like:

    {module [*mod_id*]} // where *mod_id* is the module id

  2. Now that you can call a plugin to put your module anywhere, you now need to go to the view code of your/a component you wish to add the module to and add this code:

    echo JHTML::_('content.prepare', '{module [*mod_id*]}');

Please see this link - http://www.alltogetherasawhole.org/group/developers/forum/topics/running-joomla-content-plugins - regarding point number 2. I was trying to do the same thing and I found it didn't work, and the reason for this was a comment you can find on the page link above:

"I noticed that some plugin actually expect option=com_content for them to process onPrepareContent properly, so you might actually want to "fool" them by callin JRequet::setVar and restoring the correct values after the trigger."

计㈡愣 2024-10-07 03:15:00

如果您想在 PHP 代码中显示模块,请使用此代码,它对我有用:

<?php echo   JHTML::_('content.prepare', '{loadposition position-2}');  ?>

如果您想在 html 内容中显示模块,则只需将此代码放在您想要显示模块的位置即可。

{loadposition position-2}

它加载分配给位置 2 的所有模块。

If you would like to show module within PHP code then use this code, it's worked for me :

<?php echo   JHTML::_('content.prepare', '{loadposition position-2}');  ?>

If you want to show module inside html content then just put this code where you want to show module.

{loadposition position-2}

It loads all modules which are assigned to position-2.

深白境迁sunset 2024-10-07 03:15:00

您还可以使用 Joomla 模块渲染器

$doc = JFactory::getDocument();
$renderer = $doc->loadRenderer('modules');
$position = 'custom_position_name';
$options  = array('style' => 'raw');
echo $renderer->render($position, $options, null); 

请注意,除了分配模块位置外,该模块还必须设置为“在所有页面上显示”。

You can also use the Joomla Module Renderer

$doc = JFactory::getDocument();
$renderer = $doc->loadRenderer('modules');
$position = 'custom_position_name';
$options  = array('style' => 'raw');
echo $renderer->render($position, $options, null); 

Just a heads up, Along with being assigned the module position, that module also has to be set to "Display on All pages".

灼疼热情 2024-10-07 03:15:00

Joomla 内置了此功能。您可以在内容项中使用 {loadposition XX} 命令。您可以指定模板中未出现的自定义模块位置,以确保正确的文章中包含正确的模块。

http://docs.joomla.org/How_do_you_put_a_module_inside_an_article%3F

Joomla has this functionality built in. You can use the {loadposition XX} command within your content items. You can specify custom module positions that do not appear in your template to insure that you have the correct module in the correct article.

http://docs.joomla.org/How_do_you_put_a_module_inside_an_article%3F

惟欲睡 2024-10-07 03:15:00

您可以创建一个新模块吗?

如果每个类别都出现在查询字符串 (catid=X) 中,那么您可以采用与 https://support.pillwax.com/open-source/doku.php?id=joomla:header_image

或者,该链接实际上可能会为您完成此操作。

You could create a new module?

If each category appears in the querystring (catid=X) then you could take a similar approach to https://support.pillwax.com/open-source/doku.php?id=joomla:header_image.

Alternatively, that link might actually do it for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文