Posting this to archive a twitter conversation between Vinai Kopp and myself.
I’ve long wondered what the naming conventions were for variables in Magento’s phtml template files. Many templates use the $_underscore
convention for all their variables. Other templates don’t. People have speculated that Magento is warning users not to touch these variables, since that’s been the typical semantic meaning of the underscore through programming history.
I asked twitter what was up with the underscores, and Vinai responded with two informative tweets.
To the first question he said
Yes. Convention says variables that are declared within the template should start with $_* (vs ->assign(‘var’, $val))
and when I asked about discrepancies
Oversights or not enough training for template devs 🙂 Yes, I’m afraid there are a number of those.
Eureka, concrete advice from Magento’s leading European developer trainer. Template variables are named with underscores to indicate to developers that the file you’re looking at is a template. If you’re looking to stick to Magento’s official conventions, start updating those templates!