2

We're on Magento 1.9.3.4 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

1

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.

3

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:

Mage::getStoreConfig('general/store_information/phone')

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.

0
2

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 ?>
1

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

general/store_information/phone

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"}}
0

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.

Mage::getStoreConfig('general/store_information/phone');

3
  • 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 that you have read and understand our privacy policy and code of conduct.

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