We're on Magento and we want to display the phone number in the header.

Is it ok to just put into header.phtml

<?php echo Mage::getStoreConfig('general/store_information/phone') ?>

or is it better to put it into a block and then just call it with

<?php echo  $this->getStoreNumber ?>

5 Answers 5


If possible I would add new block to header.phtml via my_layout.xml and use $this->getChildHtml('my_block') (or use an existing one).

I'd prefer <?php echo $this->getStoreNumber() ?> to seperate logic and view. In addition you will be able to rewrite this block and manipulate getStoreNumber() method.


According to the "laws" of separating business logic and presentational logic (i.e. controllers/blocks/templates), it would be better to put logic in the Block class, and only use display logic in the templates/views.

But since this is simply a single variable you retrieve from the backend, I think you can just use:


in your template.

There are exceptions however, for example imagine that the phone number would contain a comma separated list, it would be better to extract the phonenumbers in the Block than in the template, because that's easier to maintain.


Its just simple query to database no need to join query and all ,

So Its not time consuming that's why magento allows you to fetch config value in CMS block or CMS page

So Its ok to use

<?php echo Mage::getStoreConfig('general/store_information/phone') ?> 

If you want to show phone number at multiple places then I believe

You should go with block and

<?php echo  $this->getStoreNumber ?>

it is saved in core_config_data table, and the phone information is the field:


So, all you need is to read the configuration data as

$storePhone = Mage::getStoreConfig('general/store_information/phone');

For CMS pages insert the following variable

{{config path="general/store_information/phone"}}

There is no problem in using below code in header.phtml because everytime it will take dynamic value so if you change phone number in future then it will automatically change in header of your website.


  • 2
    care to explain?
    – Haim
    Jul 26, 2017 at 13:35
  • @BornCoder better leave an answer instead of writing explainations for others :)
    – sv3n
    Jul 26, 2017 at 19:18
  • 1
    Sorry guys, thought some time quick answer is better tha long explanayion :) the thing is both options will run prettty same results. So, if you like first options, feel free to use ut Jul 26, 2017 at 20:16

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.