2

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.

3
  • Did my answer solve your query? Commented Feb 28, 2018 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
    Commented Feb 28, 2018 at 12:14
  • I thought you asked about custom variable at mentioned path at admin Commented Feb 28, 2018 at 14:38

2 Answers 2

1

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();

EDIT:

As asked by @Jonas de Herdt if you want to get store specific value for the variable you just need to pass the store code along with the custom variable code as follows;

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

Reminder that you should not use objectmanager directly in your code

8
  • How to add store base url in custom varible in admin? Commented May 23, 2019 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. Commented May 23, 2019 at 7:00
  • No. I want as like {{store url ='' }} as like this added in static block content Commented May 23, 2019 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. Commented May 23, 2019 at 9:26
  • 1
    @PetarBorisovski I've already mentioned that in the answer .. Commented Nov 19, 2020 at 6:22
0

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 and acknowledge you have read our privacy policy.

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