Get magento 2 custom variable in phtml file

Arun SS picture Arun SS · Apr 8, 2016 · Viewed 12.6k times · Source

I have created a custom variable from magento 2 admin (System > Custom Variables). My custom variable code is "test_var".

How can I get that value in a phtml file?

Answer

CedCommerce picture CedCommerce · Apr 9, 2016

for this you have to use object Manager and load model using its variable Code

After that you can get its plain value, html value and its name too.

 <?php 
$model = $this->_objectManager->get('Magento\Variable\Model\Variable')->loadByCode('test_var');
$plain_value = $model->getPlainValue();
$html_value = $model->getHtmlValue();
$name = $model->getName();
?>