I have seen email templates to use built-in custom variables. Can someone explain how to use System -> Other Settings -> Custom Variables? For example category count, which will show in frontend.

  • Did my answer solve your query? – Vivek Kumar Feb 28 '18 at 11:58
  • @VivekKumar, No, I am looking for something configure variable from backend and it will work in the frontend. Like frontend showing product counts category beside. – Bojjaiah Feb 28 '18 at 12:14
  • I thought you asked about custom variable at mentioned path at admin – Vivek Kumar Feb 28 '18 at 14:38

From what I have used custom variable, it is only for passing admin manageable value to your code, you can access it as follows;

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$model = $objectManager->get('Magento\Variable\Model\Variable')->loadByCode('custom-variable-code');
$plain_value = $model->getPlainValue();

Reminder that you should not use objectmanager directly in your code

  • How to add store base url in custom varible in admin? – Emipro Technologies Pvt. Ltd. May 23 at 6:33
  • I don't know what you are trying to achieve but store url can be easily fetched using Storemanagerinterface so it doesn't need to be in admin variable. – Vivek Kumar May 23 at 7:00
  • No. I want as like {{store url ='' }} as like this added in static block content – Emipro Technologies Pvt. Ltd. May 23 at 7:06
  • I don't think that kind of wild cards are supported in variables, it is primarily meant for storing plain text or html. – Vivek Kumar May 23 at 9:26

Plain text.

But where they come in handy is that custom variables can be used in CMS style content. So pages, blocks and email templates.

This is really helpful let's say if you've got a custom telephone number that's different from store number or similar you want to come through in templates.

You should be able to insert using WYSIWYG

You would be surprised how often I see someone insert content manually which could be handled like this.

With some code change you could get these variables to come through on printed invoices etc.

Once all in place custom variable value can then be edited within admin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.