Variables are a handy little feature of a core Magento_Variable
module. Magento
allows you to create custom variables and then use them in e-mail templates, the WYSIWYG
editor, or even code expressions.
The following steps outline how we can create a new variable manually:
Magento
admin area, navigate to System | Other Settings | Custom Variables.Now that we have created the custom variable, we can use it in an e-mail template or the WYSIWYG
editor by calling it using the following expression:
{{customVar code=foggyline_hello}}
The preceding expression will call for the value of the custom
variable with code foggyline_hello
.
Variables can be used within various code expressions, though it is not recommended to rely on the existence of an individual variable, as an admin user can delete it at any point. The following example demonstrates how we can use an existing variable in the code:
$storeId =0; $variable = $this->_variableFactory->create()->setStoreId( $storeId )->loadByCode( 'foggyline_hello' ); $value = $variable->getValue( MagentoVariableModelVariable::TYPE_HTML );
The $this->_variableFactory
is an instance of MagentoVariableModelVariableFactory
.
If used in the right way, variables can be useful. Storing information such as phone numbers or specialized labels that are used in CMS pages, blogs, and e-mail templates is a nice example of using custom variables.
3.137.181.52