News:

Support the VirtueMart project and become a member

Main Menu

Menu Item's metadata not supported?

Started by Rsn, December 24, 2018, 12:24:58 PM

Previous topic - Next topic

Rsn

Why is the menu item Manufacturer Default Layout does not support metadata?

I configure metadata in the menu item (VirtueMart ยป Manufacturer Default Layout), but there are no changes on the page.
Meta description & keywords not changes.

If we add php "print_r($this)" on the manufacturer view page, we will see the metadata of menu item:

VirtuemartViewManufacturer Object
(
    ...
    [_models:protected] => Array
        (
            [manufacturer] => VirtueMartModelManufacturer Object
                (
                    ...                   
                    [state:protected] => Joomla\CMS\Object\CMSObject Object
                        (
                            ...
                            [parameters.menu] => Joomla\Registry\Registry Object
                                (
                                    [data:protected] => stdClass Object
                                        (
                                            ...
                                            [menu-meta_description] => desired text description
                                            [menu-meta_keywords] => desired text keywords

How to display them by the template?

Rsn

#1
My solution:

_my_template/html/com_virtuemart/manufacturer/default.php


<?php
        $menu_params 
$this->_models[manufacturer]->get('state')->{'parameters.menu'};
        
//echo $menu_params->get('menu-meta_description');
        //echo $menu_params->get('menu-meta_keywords');
        
$document JFactory::getDocument();
        
$document->setDescription($menu_params->get('menu-meta_description'));
        
$document->setMetadata('keywords'$menu_params->get('menu-meta_keywords'));
?>



If there are comments or suggestions, I will be grateful.
I do not exclude that this can be improved in terms of optimization.

Rsn

Or:

<?php       
        $document 
JFactory::getDocument();
        
$active JFactory::getApplication()->getMenu()->getActive();
        
$document->setDescription($active->params->get('menu-meta_description'));
        
$document->setMetadata('keywords'$active->params->get('menu-meta_keywords'));
        
$document->setTitle($active->title.' - '.JFactory::getApplication()->getCfg('sitename'));
?>