Override libraries

265 views
Skip to first unread message

Alex de Borba

unread,
Sep 26, 2014, 10:38:39 AM9/26/14
to joomla-de...@googlegroups.com
Hello to you all!

I need to override libraries/joomla/document/html/renderer/head.php in Joomla 3.3.4 but haven't found any online article that actually helps me with it.

Any tips?

Thanks in advance.

Michael Babker

unread,
Sep 26, 2014, 11:50:10 AM9/26/14
to joomla-de...@googlegroups.com
Why do you need to override a core file?

You can overload it with a system plugin at the onAfterInitialise event, but I'd suggest avoiding that at all costs as it essentially equates to hacking core by pointing an installation to a custom version of the class versus the one distributed with the package.


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/d/optout.

Dimitris

unread,
Sep 26, 2014, 12:13:57 PM9/26/14
to joomla-de...@googlegroups.com
I made a P/R few weeks ago that will allow you to do that without a plugin.

Please read all about the proposal here

And if you can make a test will be excellent as this is a prerequisite in order to have the code in the core.

Sven Versteegen

unread,
Sep 27, 2014, 3:25:09 PM9/27/14
to joomla-de...@googlegroups.com
If you want to override a renderer or create new ones just load the file, there is no plugin needed, the document checks if the renderer class is included, if not it trys to load it.
A simple require_once in your template is enough.

Sven Versteegen

unread,
Sep 27, 2014, 3:35:52 PM9/27/14
to joomla-de...@googlegroups.com
Checked your pull request, overriding html.php just to override a renderer is overkill in my eyes, like I wrote before just include your renderer and it will be used, this is possible since J!1.5.

Dimitris

unread,
Sep 27, 2014, 6:12:52 PM9/27/14
to joomla-de...@googlegroups.com
Yes that will work also:

require_once(‘my_new_header.php’);

and then call it like:

< jdoc:include type=“my_new_header” / >

Dimitris

unread,
Sep 27, 2014, 6:19:39 PM9/27/14
to joomla-de...@googlegroups.com
But is not really overkill to override html and just the renderers you need. And you can  do some pretty nice things there like minify the html document, minify js css and concatenate all js and css. Also set all the magic metas for Facebook twitter g+ etc. At the end if you know what you are doing you gain in speed and efficiency without the need for a bunch of plugins. Maybe I’ll post my core template scaffold so everybody can see the benefits of having enough flexibility by overriding the standard core renderer folder.

Sven Versteegen

unread,
Sep 27, 2014, 9:09:31 PM9/27/14
to joomla-de...@googlegroups.com
When I read your test instructions "copy the folder html from /libraries/joomla/document to protostar/document", what is the coplete Document package, it sounds to me like overkill for just overriding a renderer, sry.
Why should I copy all when all I need is the renderer class?
Maybe you get my message wrong, my english is pretty bad sorry. Also you don't need to post your core template, at least not for me, I override the head renderer since 1.5 for doing things you mentioned.
Your above example would be a new renderer, right, but you also can override the existing ones that way, again, the document class first checks if these renderer classes are already there, if they are not the core one is loaded.
So all you have to do is to create one file "renderer_head.php" (put where ever you want) and in that file define the class from the core head renderer "class JDocumentRendererHead extends JDocumentRenderer" and then include it in your template and you're done.

Sven Versteegen

unread,
Sep 27, 2014, 9:12:30 PM9/27/14
to joomla-de...@googlegroups.com
Only the html folder is of course not the complete document package... nearly 4am here sry

Dimitris

unread,
Sep 28, 2014, 6:51:41 PM9/28/14
to joomla-de...@googlegroups.com
Yes that copy the document folder is oversimplified and obviously is not needed. 
What you are writing above are all correct but there is a but. Without this code you cannot override the file e.g.: library/document/html/html.php so you have only the renderers/whatever.php. By applying this patch you have ALL the rendering procedure available to modify it at your own will WITHOUT using a plugin. 
For example I don’t use the jdoc:include shortcut and therefore no prey_match and preg_replace is needed and also I do a minification of the output, and these cannot be done without a plugin...

Sergio Manzi

unread,
Sep 28, 2014, 7:21:49 PM9/28/14
to joomla-de...@googlegroups.com
Dimitris,

I'd really like to give a look at your code: it sounds really interesting to me...

Is it on GitHub?

Thanks!

Sergio
--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send email to joomla-de...@googlegroups.com.

Dimitris

unread,
Sep 28, 2014, 7:56:50 PM9/28/14
to joomla-de...@googlegroups.com
I will try to get something in github next week, as this one I am going out of town for business. I'll post a link here.

Sergio Manzi

unread,
Sep 28, 2014, 9:25:07 PM9/28/14
to joomla-de...@googlegroups.com
Great, thanks!
Reply all
Reply to author
Forward
0 new messages