Magento 1.x
(magento 2 example below)
sectionName , group_name , and file_name are present in the moduleβs etc / system.xml file.
PHP syntax:
Mage::getStoreConfig('sectionName/groupName/fieldName');
In the administrator editor, for example, on the CMS page or in a static block; description / brief description of the catalog category, catalog product, etc.
{{config path="sectionName/groupName/fieldName"}}
To approach the work "Inside the editor", the field value must be passed through a filter for the content {{...}} to be disassembled. From this article, Magento will do this to describe categories and products, as well as CMS pages and static blocks. However, if you output the content in your own custom script view and want these variables to be parsed, you can do it like this:
<?php $example = Mage::getModel('identifier/name')->load(1); $filter = Mage::getModel('cms/template_filter'); echo $filter->filter($example->getData('field')); ?>
Substitution of the identifier / name with the corresponding values ββfor the loaded model and the field with the name of the desired attribute for the output, which may contain {{...}} entries that need to be analyzed.
Magento 2.x
From any block class that extends \ Magento \ Framework \ View \ Element \ AbstractBlock
$this->_scopeConfig->getValue('sectionName/groupName/fieldName');
Any other PHP class:
If the class (and none of its parents) inserts \Magento\Framework\App\Config\ScopeConfigInterface through the constructor, you will have to add it to your class.
// ... Remaining class definition above... /** * @var \Magento\Framework\App\Config\ScopeConfigInterface */ protected $_scopeConfig; /** * Constructor */ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig // ...any other injected classes the class depends on... ) { $this->_scopeConfig = $scopeConfig; // Remaining constructor logic... } // ...remaining class definition below...
After you entered it in your class, now you can get the store configuration values ββwith the same syntax example that is given above for block classes.
Please note that after changing the list of parameters of the __construct () class, you may need to clear the created classes, as well as the dependency injection directory: var/generation and var/di