5

Which Joomla Platform / CMS class should I extend in order to make my own custom JDOC:include tags?

I would like to have custom JDOC tags like

<JDOC:include type="scripts" />
<JDOC:include type="scripts-body" />

and a bunch of other types.

  • <JDOC:include type="scripts" /> is self explanitory, and I have a plugin in the JED to address that (named Head Tag). I have an idea of what the "scripts-body" tag would do, but please explain what you would want it to accomplish. – Michael Oct 26 '14 at 3:42
  • Maybe you could explain why you would want to do this? Apart from modules, scripts and css what would you want to add using an include statement in the template? – Seth Warburton Oct 27 '14 at 9:50
3

The solution for this question is as follows:

One needs to add a new file at the location below, to add a custom jdoc tag..

libraries/joomla/document/html/renderer/

File name should be same as the tag you are adding.. suppose one wants to use scripts as tag then file name should be scripts.php

Now in this file one needs to add a code like below. As tag name is scripts so class name should be JDocumentRendererScripts

<?php
defined('JPATH_PLATFORM') or die;

class JDocumentRendererScripts extends JDocumentRenderer
{
    public function render($scripts, $params = array(), $content = null)
    {
        $contents  = "";
        //Do your work here
        return $contents;

    }


}
?>

Now one can use custom jdoc code

| improve this answer | |
1

jdoc:include comes from the _parseTemplate() function, from the JDocumentHTML class, from the following file:

libraries\joomla\document\html\html.php
| improve this answer | |
  • _parseTemplate() is a protected function... I'm just thinking whether I'd need to implement a system plugin for this to work... ?? – J-D Oct 15 '14 at 5:49
  • Ok... I found the public function for it... it's called parse() which is part of the JDocumentHTML Class .. So I am thinking of creating a system plugin and calling my code for replacement in the onAfterRender function... Would that be right or do I need to do it BeforeRender or some of the preceding system events ?? – J-D Oct 15 '14 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.