Search code examples
joomlaoverriding

joomla com_content override


I need to make some changes in com_content/views/article/view.html.php

That file contains a class:

class ContentViewArticle extends JViewLegacy{

}

How can I override this class, because on some categories I need to set the meta description in another way than it is now?

I copied the core source file in: templates/my_template_name/code/com_content/views/article/view.html.php

I made some changes but it doesn`t work.

I think it doesn`t use the new file. I am using Joomla 2.5.7


Solution

  • You don't need to override the view.html but only the com_content/views/article/tmpl/default.php. Simply make a copy of it in

    /templates/your_template/html/com_content/article/default.php

    and edit the copy. You can then use

    $document = JFactory::getDocument();
    $document->setMetaData(...
    

    to alter the meta fields. Ultimately they will be rendered by the template so you won't need to output the metadata yourself.

    You can do the above anywhere in the component or the template, but not in the modules.