Author Topic: Menu Item's metadata not supported?  (Read 387 times)

Rsn

  • Beginner
  • *
  • Posts: 26
  • A beginner
    • Legal company LEGION
Menu Item's metadata not supported?
« on: December 24, 2018, 12:24:58 pm »
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

  • Beginner
  • *
  • Posts: 26
  • A beginner
    • Legal company LEGION
Re: Menu Item's metadata not supported?
« Reply #1 on: December 25, 2018, 06:24:01 am »
My solution:

_my_template/html/com_virtuemart/manufacturer/default.php

Code: [Select]
<?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

  • Beginner
  • *
  • Posts: 26
  • A beginner
    • Legal company LEGION
Re: Menu Item's metadata not supported?
« Reply #2 on: December 25, 2018, 10:12:57 am »
Or:
Code: [Select]
<?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'));
?>