Make Joomla automatically add a class when publish a module Topic is solved

This forum is for general questions about extensions for Joomla! 3.x.

Moderators: pe7er, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Post Reply
gabriel3
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Tue May 21, 2019 7:39 am

Make Joomla automatically add a class when publish a module

Post by gabriel3 » Wed Jun 19, 2019 2:57 pm

I'm using a module to embed videos form Fb (mod_easy_fbembeddedvideos), it works great bar the fact that not as easy as it should be (I'm using nth child at the moment).

I've tried to review the code to add it myself, but I am unable to do so.

There's a way, maybe creating an override, to instruct Joomla to automatically add a class to all modules it publish, something like "idxxx" where xxx is module id number?

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 37154
Joined: Sat Apr 05, 2008 9:58 pm

Re: Make Joomla automatically add a class when publish a module

Post by Webdongle » Wed Jun 19, 2019 3:19 pm

There is no way to to do that because the class depends on the Template. You need to create your own class and define it in the module edit screen or use an existing one.
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"The definition of insanity is doing the same thing over and over again, but expecting different results": Albert Einstein

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 25764
Joined: Mon Oct 27, 2008 9:27 pm
Location: Akershus, Norway

Re: Make Joomla automatically add a class when publish a module

Post by Per Yngve Berg » Wed Jun 19, 2019 6:35 pm

A Module Class Suffix can be used with a leading space.

https://docs.joomla.org/Module_Class_Suffix

gabriel3
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Tue May 21, 2019 7:39 am

Re: Make Joomla automatically add a class when publish a module

Post by gabriel3 » Thu Jun 20, 2019 8:09 am

Yes, but the problem here is that the extension doesn't offer the option do add a custom class or suffix.

No such field in the module edit screen/tabs.

Module is this one: https://www.joomboost.com/joomla-module ... ideos.html

It has an option to choose the module tag (div, section, etc) but it seems it's not working, either.
Last edited by gabriel3 on Thu Jun 20, 2019 8:45 am, edited 1 time in total.

venci
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Sat Nov 17, 2012 6:10 am

Re: Make Joomla automatically add a class when publish a module

Post by venci » Thu Jun 20, 2019 8:43 am

Hi gabriel3,
Use this sample code

Code: Select all

<div class="mydivclassname<?php echo $module->id;?>">
Code here .....
</div>

gabriel3
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Tue May 21, 2019 7:39 am

Re: Make Joomla automatically add a class when publish a module

Post by gabriel3 » Thu Jun 20, 2019 8:47 am

venci wrote:
Thu Jun 20, 2019 8:43 am
Hi gabriel3,
Use this sample code

Code: Select all

<div class="mydivclassname<?php echo $module->id;?>">
Code here .....
</div>
Looks great, thanks. Where I find the code that Joomla uses to publish a module? (to wrap your code around).
I cannot add that into mod's default.php file as that publish just the "inmost" part of the module (i.e. not the title, for example) so if I need to change the modeule backgound I need the class to be declared before.

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 37154
Joined: Sat Apr 05, 2008 9:58 pm

Re: Make Joomla automatically add a class when publish a module

Post by Webdongle » Thu Jun 20, 2019 9:02 am

Create an override for the module and edit the override so it's div has a new class
e.g. <div class="originalclass addtionalclass"
Then add the .addtionalclass to your css (best make a copy of the Template and edit/use the copy)
Or
Use an extension that is written correctly.
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"The definition of insanity is doing the same thing over and over again, but expecting different results": Albert Einstein

venci
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Sat Nov 17, 2012 6:10 am

Re: Make Joomla automatically add a class when publish a module

Post by venci » Thu Jun 20, 2019 9:05 am

Hi,
I am not familiar with the module about which is your question.
The code that I suggest just adds to the name of the div class - number of the module.
This makes the name of the div class for each copy of the module unique.
Note: With the code I specified can change the name of the Div class that comes with the module.

gabriel3
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Tue May 21, 2019 7:39 am

Re: Make Joomla automatically add a class when publish a module

Post by gabriel3 » Thu Jun 20, 2019 9:40 am

Webdongle wrote:
Thu Jun 20, 2019 9:02 am
Create an override for the module and edit the override so it's div has a new class
e.g. <div class="originalclass addtionalclass"
Then add the .addtionalclass to your css (best make a copy of the Template and edit/use the copy)
I think this would not work.
fbvideomod.jpg
Module's default.php starts printing stuff in "B".
I need a class in "A" to apply a style to the whole module (i.e. a custom background).

I cannot use .module or .clearfix as every module in #maintop3 has these classes.
You do not have the required permissions to view the files attached to this post.

venci
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Sat Nov 17, 2012 6:10 am

Re: Make Joomla automatically add a class when publish a module

Post by venci » Thu Jun 20, 2019 9:55 am

Hi gabriel3

In your code, make the following change
from

Code: Select all

 
 <div id="fb-root" class="fb_reset"......
to

Code: Select all

<div id="fb-root" class="fb_reset_<?php echo $module->id;?>" ....
NB: Before making the changes, make a copy of your original files

gabriel3
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Tue May 21, 2019 7:39 am

Re: Make Joomla automatically add a class when publish a module

Post by gabriel3 » Thu Jun 20, 2019 10:05 am

Thanks but I need the class in "A". "B" is to deep in the structure.
class_here.jpg
You see, other modules allows to add a class when the module is first inserted into the page.

That's why I asked if there's a way to have Joomla add the module id, because that's part is not code from the mod, but I think it's code from core Joomla or the template, but I don't know where it is.

The only option I have now, bar counting modules with the child option, opening to issues if later modules are added or moved up or down, is to add the desired background for Fb videos to all modules in #maintop3, then add classes to EVERY other modules (not Fb videos, and that allows to specify a class) to REMOVE the background.
You do not have the required permissions to view the files attached to this post.

venci
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Sat Nov 17, 2012 6:10 am

Re: Make Joomla automatically add a class when publish a module

Post by venci » Thu Jun 20, 2019 10:24 am

In my opinion, this requires a change in the code of the template.
I'm not sure this is the right approach when you want to change the module parameters.
If someone with more experience to share their opinion would be useful for the community.

gabriel3
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Tue May 21, 2019 7:39 am

Re: Make Joomla automatically add a class when publish a module

Post by gabriel3 » Thu Jun 20, 2019 10:25 am

gabriel3 wrote:
Thu Jun 20, 2019 10:05 am
The only option I have now, bar counting modules with the child option, opening to issues if later modules are added or moved up or down, is to add the desired background for Fb videos to all modules in #maintop3, then add classes to EVERY other modules (not Fb videos, and that allows to specify a class) to REMOVE the background.
Done. My actual code looks like this:
modfb3.jpg

Code: Select all

#maintop3 .module {
    background: #02378B;
    padding: 1em;
}
#maintop3 .module.bkg_none {
    background: none;
}
Modules A and C are a custom 3rd party mod that publish Fb Videos and DOES NOT ALLOW to specify a class.

All other modules inside #maintop3 are different kind of modules, that allows for custom class(es) that I used to remove the background from them.

This is obviously a workaround, but the correct course of action (apply the background just to the module I wanted to have it) was not a viable one.
You do not have the required permissions to view the files attached to this post.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 25764
Joined: Mon Oct 27, 2008 9:27 pm
Location: Akershus, Norway

Re: Make Joomla automatically add a class when publish a module

Post by Per Yngve Berg » Thu Jun 20, 2019 11:33 am

Read up on Module Chrome in the docs.

gabriel3
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Tue May 21, 2019 7:39 am

Re: Make Joomla automatically add a class when publish a module

Post by gabriel3 » Thu Jun 20, 2019 1:00 pm

I did it!
I managed to do what I originally wanted to: add a class with module id to each module.

I've edited the file /html/modules.php into the template folder

from:

Code: Select all

<div class="module <?php echo $modclass_sfx ?> clearfix"> 
to:

Code: Select all

<div class="module <?php echo " id".$module->id." ".$modclass_sfx; ?> clearfix">
This is the result:
modfb4.jpg
You do not have the required permissions to view the files attached to this post.

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 37154
Joined: Sat Apr 05, 2008 9:58 pm

Re: Make Joomla automatically add a class when publish a module

Post by Webdongle » Thu Jun 20, 2019 1:01 pm

Then make a copy of the Template and edit the class for the div of the module position that you are placing the module that is coded correctly.

Addendum
an override was the answer then
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"The definition of insanity is doing the same thing over and over again, but expecting different results": Albert Einstein

gabriel3
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Tue May 21, 2019 7:39 am

Re: Make Joomla automatically add a class when publish a module

Post by gabriel3 » Thu Jun 20, 2019 1:18 pm

I don't get what you're telling me, sorry...
afaik /html/modules.php into the template folder is already an override :)

Anyway, everything inside of #maintop3 is created dynamically by Joomla depending on what module(s) I assign to that specific position (maintop3 is a position in the template currently in use), so I cannot manually edit anything inside it, even less I could be able to edit one specific div as these are generated by Joomla+relative module extension(s).

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 37154
Joined: Sat Apr 05, 2008 9:58 pm

Re: Make Joomla automatically add a class when publish a module

Post by Webdongle » Thu Jun 20, 2019 1:42 pm

gabriel3 wrote:
Thu Jun 20, 2019 1:18 pm
I don't get what you're telling me, sorry...
afaik /html/modules.php into the template folder is already an override ...
Yes and editing it was editing an override. The solution was with editing an override be it an override that already existed or by creating one to edit.
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"The definition of insanity is doing the same thing over and over again, but expecting different results": Albert Einstein


Post Reply

Return to “Extensions for Joomla! 3.x”