I see something like the below in magento

<?php echo $this->__('* Required Fields') ?>

Why can't I simply use

<?php echo "Required Fields" ?>

The output seems to be the same in both cases. What is the function of the $this->__ . I see this usage in a lot of places and would like to clear any misunderstanding I may be having.

Any help greatly appreciated.


The main difference is that this:

<?php echo $this->__('* Required Fields') ?>

Allows for front end translations through a CSV file or through the Admin Panel (Configuration -> Developer -> Translate Inline)

Where as:

<?php echo "Required Fields" ?>

Will not allow you to use the translation features.

| improve this answer | |
  • Best practice is to use the $this->__('echo text here') - your site is English now but maybe down the line it will require additional languages. The code you posted gets the username of a logged in user. – SR_Magento Jul 14 '15 at 18:31
  • Thanks - that helps. I tried searching for the nature of escapeHtml ? What exactly is this doing ? why couldn't I simply have done $this->getUsername(). – Vinu D Jul 14 '15 at 18:34
  • Post a new question :) – SR_Magento Jul 14 '15 at 18:38
  • Matter of time before someone said that - I was asking for it :) – Vinu D Jul 14 '15 at 18:39
  • 2
    Even if your site is only in English, to might want to change texts per theme or store without having to change them in all templates. Regarding escapeHtml(): You want to be sure that it also works if the translation has funny characters. See: magento.stackexchange.com/questions/569/… – Fabian Schmengler Jul 21 '15 at 12:59

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.