Closed reilldesign closed 8 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?
This works fine even when the menu alias is called. As long as there is no other recommendation i use this way.
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:
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);
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');
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');
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');
@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) "." }
with $this->params['menu'] I cannot retrieve my self-defined params.
Then thats a bug.
@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:
Open the xml file of your menu item template
Add a new field into the xml file
Create a new menu item and add a value to your custom menu param. Click save and close.
Access the custom menu param in your template file like the following:
$this->params['menu']->get('page_title', 'Default Title', 'string');
Here follows a detail documentation how to use component inherited configuration parameters which can be overritten in categories, images and manu items ...
Select a name for your parameter. The parameter name has to start with jg_
. In this example I will use jg_example
.
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.
Add your parameter to the configuration sets database table by adding a corresponding line to the sql installation file
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.
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
.
After that you can go to the configuration manager and you will find the new created parameter in the corresponding tabs.
Access the custom menu param in your template file like the following:
$this->params['component']->get('jg_example', '', 'string');
Optional: Add your parameter to the category edit form xml in the backend.
Add the field in the fieldset named "general"
After that your parameter will show up in the category edit form view in the backend.
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.
Optional: Add your parameter to the category edit form xml in the frontend, the same way we did for the backend.
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.
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?