Old plugin configuration - deprecated

You can define multiple options that will be displayed in the Plugins » Plugin overview menu to be configured by users. The value of each option can be accessed in your PHP code by using the ConfigRepository or from Twig templates by using the config() macro.

All admin options can be defined in an array of configurations in the config.json. Each configuration needs the following properties:

PluginXY/config.json
[
    {
        "tab"       : "Categories",
        "key"       : "global.category.home",
        "label"     : "Home page",
        "type"      : "category_select"
    },
    {
        "tab"       : "Header",
        "key"       : "header.company_logo_align",
        "label"     : "Align company logo",
        "type"      : "dropdown",
        "possibleValues": {
            "0" : "Left",
            "1" : "Center",
            "2" : "Right"
        },
        "default"   : "0"
    },
    {
        "tab"       : "Footer",
        "key"       : "footer.col_1_title",
        "label"     : "Title of first column",
        "type"      : "text",
        "default"   : "Shop"
    },
    {
        "tab"       : "SEO",
        "key"       : "seo.text_area",
        "label"     : "Text for search engines",
        "type"      : "textarea",
        "default"   : "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."
    },
    {
        "tab"       : "Item",
        "key"       : "item.data",
        "label"     : "Show item information",
        "type"      : "multi_select",
        "possibleValues": {
            "item.technical_data": "Technical data",
            "item.description": "Description"
        },
        "default"   : "all"
    },
    {
       "tab"       : "Basket",
       "key"       : "basket.variations",
       "label"     : "Show Change variation button",
       "type"      : "checkbox",
       "default"   : true
   }
]
Property Description
tab Organises the config.json options into tabs. Tabs are optional.
key The identifier of the configuration. This key can be used to access the options value.
label The label of this configuration. Will be displayed in the Plugins » Plugin overview menu.
type Defines the presentation of this configuration. Possible values:
"dropdown" = Possible values are displayed in a drop-down menu.
"text" = Displays a text field for text input.
"textarea" = Displays a text area for text input.
"checkbox" = Displays a checkbox.
"multi_select" = Displays a multi-select box. Possible values can be activated or deactivated.
"category_select" = Displays a category picker.
"password" = Displays a password field for text input that will not be displayed as clear text.
possibleValues Defines available values of a dropdown or multi-select option (obsolete if type is "text", "checkbox" or "category_select")
default The default value of this option

You can convert your config.json to the new format with this tool.

Accessing plugin options from PhpClass.php

    // access configuration from PHP
    function getTitle(ConfigRepository $config):string
        {
            if( $config->get('MyPlugin.show_title') == "1" )
                {
                    return $config->get('MyPlugin.title_text');
                        }
                            else
                        {
                    return "";
                }
        }
    

Accessing plugin options from Template.twig

    
    {% if config('MyPlugin.show_title') == "1" %}
        <h1>{{ config('MyPlugin.title_text') }}</h1>
    {% endif %}
    
    

Is this article helpful?

 

Thank you for your Feedback

you can close this field now!