? ? Success

User tests: Successful: Unsuccessful:

avatar dgt41
dgt41
1 Aug 2014

In Joomla! if you want to override something you have to put it in the active template directory (e.g.: the layouts goes in (active template)/html/layouts).
This PR introduces the ability to override the whole rendering process in the template by copying (and modifying per your preferences) the /libraries/joomla/document directory.

It shouldn't rise any backward compatibility issues (except that the directory [active template]/document might be in use?).

What this PR might provide to Joomla! devs/users?
Flexibility on the way that the template renders the data (the inner logic). e.g. someone may use echo $this->getBuffer('modules', 'menu', array('menu', 'html5')); and remove the <jdoc.. > parser.

Why?
Because this is one area that if you want to override and use your own logic you have to do it through a plugin (this is way easier and cleaner)

Feature tracker: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=34027

avatar dgt41 dgt41 - open - 1 Aug 2014
avatar jissues-bot jissues-bot - change - 1 Aug 2014
Labels Added: ? ?
avatar dgt41 dgt41 - change - 1 Aug 2014
Title
Add ability to override the renderer
Add ability to override the renderer [New feature]
avatar dgt41 dgt41 - change - 1 Aug 2014
The description was changed
Title
Add ability to override the renderer
Add ability to override the renderer [New feature]
Description <p>In Joomla! if you want to override something you have to put it in the active template directory (e.g.: the layouts goes in (active template)/html/layouts).<br> This PR introduces the ability to override the whole rendering process in the template by copying (and modifying per your preferences) the /libraries/joomla/document directory.</p> <p>It is shouldn't rise any backward compatibility issues (except that the directory [active template]/document might be in use?).</p> <p>What this PR might provide to Joomla! devs/users?<br> Flexibility on the way that the template renders (the inner logic) the data. e.g. someone may use echo $this-&gt;getBuffer('modules', 'menu', array('menu', 'html5')); and remove the parser.</p> <p>Why?<br> Because this is one area that if you want to override and use your own logic you have to do it through a plugin (this is way easier and cleaner)</p> <p>In Joomla! if you want to override something you have to put it in the active template directory (e.g.: the layouts goes in (active template)/html/layouts).<br> This PR introduces the ability to override the whole rendering process in the template by copying (and modifying per your preferences) the /libraries/joomla/document directory.</p> <p>It shouldn't rise any backward compatibility issues (except that the directory [active template]/document might be in use?).</p> <p>What this PR might provide to Joomla! devs/users?<br> Flexibility on the way that the template renders (the inner logic) the data. e.g. someone may use echo $this-&gt;getBuffer('modules', 'menu', array('menu', 'html5')); and remove the parser.</p> <p>Why?<br> Because this is one area that if you want to override and use your own logic you have to do it through a plugin (this is way easier and cleaner)</p> <p>Feature tracker: <a href="http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&amp;tracker_item_id=34027">http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&amp;tracker_item_id=34027</a></p>
avatar dgt41 dgt41 - change - 1 Aug 2014
Title
Add ability to override the renderer [New feature]
[#34027] Add ability to override the renderer [New feature]
avatar dgt41 dgt41 - change - 1 Aug 2014
Title
Add ability to override the renderer [New feature]
[#34027] Add ability to override the renderer [New feature]
avatar Bakual Bakual - change - 2 Aug 2014
Labels Added: ?
avatar Bakual
Bakual - comment - 2 Aug 2014

You need to make the change to the property name also in the later checks to $this->_file

avatar brianteeman brianteeman - change - 2 Aug 2014
Labels Added: ?
Removed: ?
avatar Bakual
Bakual - comment - 3 Aug 2014

You need to change $this->_file to $this->file :smile:

avatar Bakual
Bakual - comment - 5 Aug 2014

The error was that you changed the property declaration correctly from public $_file = ''; to public $_file = '';. But you didn't apply this change in the rest of your code where you still used $this->_file instead of $this->file.
That created the "undefined variable" notices which broke Travis.

avatar dgt41
dgt41 - comment - 5 Aug 2014

In the logic the var is $this->_file from the array is fine. If I don’t declare it travis fail. If I declare is as $file I still have to get the content from $this->_file. I think I will remove the declaration and do it in the unit test file

avatar dgt41
dgt41 - comment - 5 Aug 2014

Test istructions:

Apply the patch
assuming selected template: protostar
create directory named document in /templates/protostar
copy the folder html from /libraries/joomla/document to protostar/document
So you have /templates/document/html/html.php
edit html.php (in protostar foolder...)
In the last fuction _fetchTemplate()
replace the line before return so it will be like
$this->_template = $this->_loadTemplate($directory . '/' . $template, $file). '<!-- comment -->';
(Add a comment after the document)
Refresh the page, see the source at the bottom you should have <!-- comment -->
You just overrided the render!

What you can do if this gets accepted?

Because renderers are the place where the code gets from arrays and strings to actual html, xml, raw, feed or json, you can do pretty much whatever you want.
Some examples of creative code that can be put in the renderers:
Put custom code in renderer html (eg minifier, remove <JDoc )
Create custom code for head (e.g.. scripts and css concatenation, custom metas)
Mesh around with the error page and feed in creative ways
Or go all the way and get mustache or twig in the template

avatar Bakual
Bakual - comment - 5 Aug 2014

In the logic the var is $this->_file from the array is fine. If I don’t declare it travis fail. If I declare is as $file I still have to get the content from $this->_file. I think I will remove the declaration and do it in the unit test file

Declaring the property in the unit test certainly is the wrong approach to fix it. That will never be accepted.

Currently I'm wondering where you intend to set the $this->_file property. Before your PR it doesn't seem to be used anywhere. So I assume you introduced it and meant to set it directly somehow.
But then it should be $this->file according to our coding rules as I stated. Properties starting with underlines are meant to be private properties.
And of course it should also be initialised before using it by adding the public $file = ''; as you did originally.

avatar Bakual
Bakual - comment - 5 Aug 2014

Also you're restricting this feature now only to the frontend. Why?

avatar dgt41
dgt41 - comment - 5 Aug 2014

Ok, I’ll give it another try…
As for the restriction only in front end: there are not that many templates for admin…
I’ll revert that as well
@Bakual About $this->_file: All is needed here is the directory of the current template, dirname($this->_file) provides this very inexpensive. Getting it through $template = $app->getTemplate(); is a lot more intense work (many calls on many files, even db query). So what I really meant was the code to be really efficient.

avatar Bakual
Bakual - comment - 5 Aug 2014

Ah, so $this->_file is set somewhere from outside the class? Do you know where this is set?

Then of course we can't rename it, sorry for that then. But imho it should still be initialised.

avatar Bakual
Bakual - comment - 5 Aug 2014

Found it. It's used in JDocumentError (https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/document/error/error.php#L131) and JDocumentHtml (https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/document/html/html.php#L572).
But it's not a property which is always set in JDocument. So you can't count on that one being there.
However it may be that you only want to override it for HTML documents anyway, Then you should look at making that change in JDocumentHtml instead.

avatar dgt41
dgt41 - comment - 5 Aug 2014

Maybe something like this will make a good fit: if ($type == ‘html’ || $type == ‘error’) {$this->file… } else {$template = $app->getTemplate(); … } ?

avatar Bakual
Bakual - comment - 5 Aug 2014

No, that looks like messy code to me.
Just override the loadRenderer method in JDocumentHtml (and JDocumentError if that's needed) if you think it's important enough.

avatar dgt41
dgt41 - comment - 5 Aug 2014

Actually the code as i tested will be like

            $path = __DIR__ . '/' . $this->_type . '/renderer/' . $type . '.php';

            if (!empty($this->_file) && file_exists(dirname($this->_file) . '/document/' . $this->_type . '/renderer/' . $type . '.php'))
            {
                $path = dirname($this->_file) . '/document/' . $this->_type . '/renderer/' . $type . '.php';
            }
            else
            {
                $template = $app->getTemplate();
                if (file_exists( JPATH_THEMES .'/' . $template . '/document/' . $this->_type . '/renderer/' . $type . '.php'))
                {
                    $path =  JPATH_THEMES .'/' . $template . '/document/' . $this->_type . '/renderer/' . $type . '.php';
                }
            }

            if (file_exists($path))
            {
                require_once $path;
            }
            else
            {
                throw new RuntimeException('Unable to load renderer class', 500);
            }
avatar Bakual
Bakual - comment - 5 Aug 2014

That looks fine, yes.

avatar dgt41
dgt41 - comment - 5 Aug 2014

On the other hand additional renderers function loadRenderer($type) are available only in html and feed and makes me wonder if this is the best approach here. I’ll give it some thought...

avatar dgt41
dgt41 - comment - 6 Aug 2014

This PR got really meshy, therefore I am closing it and opening a new one.

I forgot: Big thanx to Thomas @Bakual for his help!

avatar dgt41 dgt41 - change - 6 Aug 2014
Status New Closed
Closed_Date 0000-00-00 00:00:00 2014-08-06 09:40:01
avatar dgt41 dgt41 - close - 6 Aug 2014
avatar dgt41 dgt41 - close - 6 Aug 2014
avatar dgt41 dgt41 - head_ref_deleted - 11 Sep 2014

Add a Comment

Login with GitHub to post a comment