A module is nothing more than a small class with some conventions. One of the conventions is that it has to have a method called toString. If you add the module to an asset, that function is called automatically when this asset is rendered.
But you do not need to add the module anywhere. You can simply use its toString method anywhere else. Look at how @AjansKartal has done it in his question.
When you do not use the addModule method, it will not be automatically rendered anywhere.
There is a plugin called "eventi" which is helpful when trying to find the event you need to hook.
As far as I understand, the "Head" asset is rendered in the html <head> tag. If you want to add anything in the head tag, a module is the wrong way.
The head is rendered by module on its own and that module provides some useful functionalities, like adding css files, or adding any tag you like. Maybe you should start a new discussion since this seems to be a complete new topic and describe what you want to add the head.
But you are correct with "You can't add it between the #Head and the #Content". I agree that JavaScript would be the only option, if it couldn't be solved with CSS.
Just one last thought: a custom theme would be a solution, but it isn't always an option. With a custom theme you could insert a {asset name="MyTarget"} which you can address.
Yes, even though the names are the same they are two different things. asset head is the head of the document .
The page structure #Head is an asset too but in another context within html structure. I know it's confusing... Head should be called #Top but people would be angry because Headers...
To do it you could
a.create a whole new asset called #BetweenHead
b.add a new div to the template containing that asset
c.use jQuery to append or prepend sections
I suffered this truth myself as I wanted to add a module between the Menu and the Body.
Targeting the #Body , puts it before the body above everything.
Comments
It would be great to have settings where one can add the modules to the array via the dashboard.
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
@r_j Good morning, I know that it is possible to insert the module in the head, simply placing:
return 'Head';
Now I would like to know how to place it before or after the head, which function would be used and again
Regards,
A module is nothing more than a small class with some conventions. One of the conventions is that it has to have a method called
toString
. If you add the module to an asset, that function is called automatically when this asset is rendered.But you do not need to add the module anywhere. You can simply use its
toString
method anywhere else. Look at how @AjansKartal has done it in his question.When you do not use the addModule method, it will not be automatically rendered anywhere.
@r_j ok, perfect, I understand, but I do not understand how to call the module in (before head, head, after head),
Regards,
There is a plugin called "eventi" which is helpful when trying to find the event you need to hook.
As far as I understand, the "Head" asset is rendered in the html
<head>
tag. If you want to add anything in the head tag, a module is the wrong way.The head is rendered by module on its own and that module provides some useful functionalities, like adding css files, or adding any tag you like. Maybe you should start a new discussion since this seems to be a complete new topic and describe what you want to add the head.
No @R_J he does not want to add modules or anything to the document head, he is referring to the asset #Head .
You can't add it between the #Head and the #Content because that would be the #Body and as far as I know the #Body is not an asset it's a container.
What I have done to add something there, I used jQuery to append to the #Head
or use prepend to go before.
If you target #Body , it will show before the #Head I believe, it was a while ago that I dealt with that.
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
It sounds reasonable what you say, @vrijvlinder, but when I look at the template I see this:
So the "Head" asset is in between the head tags.
You are refering to the html structure and the div IDs
But you are correct with "You can't add it between the #Head and the #Content". I agree that JavaScript would be the only option, if it couldn't be solved with CSS.
Just one last thought: a custom theme would be a solution, but it isn't always an option. With a custom theme you could insert a
{asset name="MyTarget"}
which you can address.Yes, even though the names are the same they are two different things. asset head is the head of the document .
The page structure #Head is an asset too but in another context within html structure. I know it's confusing... Head should be called #Top but people would be angry because Headers...
To do it you could
a.create a whole new asset called #BetweenHead
b.add a new div to the template containing that asset
c.use jQuery to append or prepend sections
I suffered this truth myself as I wanted to add a module between the Menu and the Body.
Targeting the #Body , puts it before the body above everything.
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌