JoomGalleryfriends / JG4-dev

Development repository for JoomGallery v4.x
GNU General Public License v3.0
10 stars 6 forks source link

category menu view params #143

Closed reilldesign closed 8 months ago

reilldesign commented 11 months ago

I'm trying to access the parameters in the layout file component/joomgallery/tmpl/category/default.php

For example: $category_class = $this->params->get('category_class');

But the $category_class is empty. All three new params in the xml file are printed in the url

.../gallery.html?num_columns=3&category_class=masonry&caption_align=left

What is the recommended way to get those params?

MrMusic commented 11 months ago

You are trying to access a parameter that you have defined in default.xml file? You probably have to read the parameter in the HtmlView.php first. Example parameter "spalten":

$input  = Factory::getApplication()->input;
$this->params['spalten'] = $input->getInt('spalten', '1');

then you can get the parameter in the default.php:

$countcolumns = $this->params['spalten'];

Maybe there are other ways?

reilldesign commented 11 months ago

This works fine even when the menu alias is called. As long as there is no other recommendation i use this way.

Elfangor93 commented 11 months ago

In JoomGallery the main configuration parameters are threated with the coniguration service and are set within the configuration sets in the backend or in the params tab of the edit forms of the content types (e.g. images). Besides that you may need to get parameters from the menu item, for example if you have set your own parameters in a template override. Here you find a list of how to get the different coniguration parameters in the view or template files in the frontend:

Joomla global configuration parameters

The global configuration is set in Backend->System->Global Configuration->System->Global Configuration. You can get a parameter from it by using $this->app->get('sitename', 'Default name', string);

Component global configuration parameters

The component global configuration is set in Backend->System->Global Configuration->Component->JoomGallery. You can get a parameter from it by using $this->params['component']->get('inheritance_config', 'default', 'string');

Component inherited configuration based on sets

This are the configurations set in the configuration sets in the JoomGallery Backend. They are threaten with the coniguration service using the following overriding hierarchy: Menu Item > Image > Category > Custom Configuration Set > Global Configuration Set. Parameters in this configuration all start with jg_. You can get a parameter from it by using $this->params['configs']->get('jg_imagetypes', '', 'string');

Menu item configuration parameters

This parameters are set in each menu item and may contain parameters belonging to the components configuration sets. Do not use this approach to get this ones but use the approach explained above. If you want to get menu item parameters that are not threated as configuration set parametern (without jg_ in the beginning) then you can get this by using $this->params['menu']->get('page_title', 'Default Title', 'string');

reilldesign commented 11 months ago

@Elfangor93 with $this->params['menu'] I cannot retrieve my self-defined params. The var_dump lists only the Joomla specific params. With com_content ovverides it is possible to expand the xml and retrieve the params. The goal should be to configure the global Joomgallery settings by each menu item individually.

var_dump($this->params['menu']);

object(Joomla\Registry\Registry)#1116 (3) { ["data":protected]=> object(stdClass)#1113 (13) { ["menu-anchor_title"]=> string(0) "" ["menu-anchor_css"]=> string(18) " grid-item--width2" ["menu_icon_css"]=> string(0) "" ["menu_image"]=> string(0) "" ["menu_image_css"]=> string(0) "" ["menu_text"]=> int(1) ["menu_show"]=> int(1) ["page_title"]=> string(0) "" ["show_page_heading"]=> string(0) "" ["page_heading"]=> string(7) "Gallery" ["pageclass_sfx"]=> string(0) "" ["menu-meta_description"]=> string(0) "" ["robots"]=> string(0) "" } ["initialized":protected]=> bool(true) ["separator":protected]=> string(1) "." }

Elfangor93 commented 11 months ago

with $this->params['menu'] I cannot retrieve my self-defined params.

Then thats a bug.

Elfangor93 commented 10 months ago

@reilldesign I just tried it by myself and it works. But be aware, that this way you can not set the parameter in the global configuration but only in the menu item. If you want a global configuration parameter which can be overritten in the menu item, use a component inherited configuration parameter instead.

Here follows a detail documentation how to do it use menu item dedicated configuration parameters:

Menu item configuration parameters

  1. Open the xml file of your menu item template grafik

  2. Add a new field into the xml file grafik

  3. Create a new menu item and add a value to your custom menu param. Click save and close. grafik

  4. Access the custom menu param in your template file like the following: $this->params['menu']->get('page_title', 'Default Title', 'string');

grafik

  1. Check in the frontend that your custom parameter is respected in your chosen template grafik
Elfangor93 commented 10 months ago

Here follows a detail documentation how to use component inherited configuration parameters which can be overritten in categories, images and manu items ...

Component inherited configuration based on sets

  1. Select a name for your parameter. The parameter name has to start with jg_. In this example I will use jg_example.

  2. Add at least two language constants for your parameter to the com_joomgallery.ini file of the backend. The name of the language constants has to match with your chosen name. grafik

  3. Add your parameter to the configuration sets database table by adding a corresponding line to the sql installation file grafik

grafik grafik

  1. Add your parameter to the configuration form xml grafik

grafik I want the parameter to be shown in the "Frontend Views" tab and there in the sub tab "Common Settings". Thats why I added the field under the fieldset "fontend" and sub-fieldset "frontend-general". As label and description I used the previously created language constants.

  1. At this point you have to uninstall and reinstall the component or to manually add the new column declared in step 3 to the database table #__joomgallery_configs.

  2. After that you can go to the configuration manager and you will find the new created parameter in the corresponding tabs. grafik

  3. Access the custom menu param in your template file like the following: $this->params['component']->get('jg_example', '', 'string');

  4. Optional: Add your parameter to the category edit form xml in the backend. grafik

Add the field in the fieldset named "general" grafik

  1. After that your parameter will show up in the category edit form view in the backend. grafik When adding a value to the category, the parameter value set in the config manager will be overritten for this category with the value eneterd here in the category form.

  2. Optional: Add your parameter to the category edit form xml in the frontend, the same way we did for the backend.

  3. Optional: Add your parameter to a menu item template by adding the corresponding field to the xml file of the menu item template. This has to be done the same way as you would add menu item configuration parameter. The difference is that you use now a parameter name starting with jg_. This marks it as a component inherited configuration parameter.