nican VIP
Total posts: 392
29 Июль 2015 12:35

Hello, I am trying to display a module ("BAnners" module) inside a Cobalt record, to do this I have inserted the sintax

<div class="article-banner"> <jdoc:include type="modules" name="article-top"/> </div>

inside my record full view template

Now... I do have a module published in "article-top" position but when I visit any Cobalt record (eg. Click here to link...)

I do not see the module (which should be right below the record title)

<?php if($params->get('tmpl_core.item_title')):?>

        <?php if($this->type->params->get('properties.item_title')):?>

            <div class="page-header">

                <<?php echo $params->get('tmpl_params.title_tag', 'h1')?>>

                    <?php echo $item->title?>

                    <?php echo CEventsHelper::showNum('record', $item->id);?>

                </<?php echo $params->get('tmpl_params.title_tag', 'h1')?>>

            </div>

        <?php endif;?>

    <?php endif;?>

    <div class="clearfix"></div>

<div class="article-banner"> <jdoc:include type="modules" name="article-top"/> </div>

If I inspect the code I can clearly see the custom code I ahve inserted, only that no module is being rendered

I have double checked to ahve a module pulished in that position, with no particular restrictions as per menu items, joomla groups and so on... evrything seems fine so I am starting to think that I am missing something basic here, if only I knew what!

Thank you for any advice :-)

Последние изменения: 04 Авг 2015


jimie VIP
Total posts: 531
29 Июль 2015 13:08

Hello

See if this helps you:

<?php
jimport('joomla.application.module.helper');
$modules = JModuleHelper::getModules('your-position');
foreach($modules as $module)
{
        echo JModuleHelper::renderModule($module);
}

?>

Rgds


nican VIP
Total posts: 392
29 Июль 2015 15:44

Thanks Jimie, your code is working!

How should I edit it if I want to insert the module in a div with a css class, and the div must be displaied only if there is a module published in that position?

This is the banners component module, not a custom html one, this is why I want the code inside a div with a css class

Thanks!


pepperstreet VIP
Total posts: 3,837
30 Июль 2015 01:32

oloccina insert the module in a div with a css class

I guess, you can use and output the regular module backend parameters:

  • Module Class Suffix
  • Module Chrome i.e. xhtml or html5 if you need to set bootstrap-size, too.

Please, enter parameters and check the page source.
Does it output those parameters already?

If not, you might set and override them programatically...
For instance the Module Chrome style like so:

$attribs['style'] = 'xhtml';
echo JModuleHelper::renderModule( $module, $attribs );

Related article in Joomla Docs.


nican VIP
Total posts: 392
30 Июль 2015 09:26

pepperstreet I guess, you can use and output the regular module backend parameters:

Thankks Pepperstreet

Yes, I tried that, by adding a "banner" class to the module class suffix parameter

but for some reason when the module is being displaied the class is "itembanner" so it doesn't work

I think maybe because this is a "Banners component" module, Joomla automatically add the "item" class to it, I also tried to insert " banner" (with a space bfore the class name) in the module class suffix parameter, but the output is still "itembanner"

probably inserting themodule inside a div with a css class instead would be a way to solve this...


pepperstreet VIP
Total posts: 3,837
31 Июль 2015 04:17

oloccina I also tried to insert " banner" (with a space bfore the class name) in the module class suffix parameter, but the output is still "itembanner"

Strange. AFAIK, it works in the latest Joomla version. The SPACE character is important and works for me in the regular module output. I can see MY_SUFFIX on the Item and the surrounding DIV.

Although it might depend on the current template/modules.php ! Remember to check the parameter "Module Style". This has an important impact on the final output. Sometimes 3rdParty templates have special overrides, or simply forgot to output the SUFFIX at all!


nican VIP
Total posts: 392
04 Авг 2015 09:23

pepperstreet Remember to check the parameter "Module Style".

Thank you, I'll check that!


pepperstreet VIP
Total posts: 3,837
04 Авг 2015 11:19

oloccina

pepperstreet Remember to check the parameter "Module Style".

Thank you, I'll check that!

I just tested with the regular Joomla main template syntax. Not programatically! So it might be possible, that the "render" code takes only the defaults/or nothing. Probably you would have to set each option... I don't know it for sure.

Работает на Cobalt