Magento News

 

Accessing custom variables from a .phtml in Magento

I have a file (js.phtml) where my code executes. I need to access some user data. When I error_log($this) in js.phtml, it displays, “Mage_Core_Block_Template” – which is confusing to me. I would expect that to be the parent class, not the value of the class getting passed to my .phtml file.

So, how do I supply the .phtml file with custom objects or methods? I’m super new to Magento and I’ve just been dropped into a task, so I apologize for possibly using incorrect terminology.

Edit:
My full file path is:

  • /app/design/frontend//default/template/customer/welcome/js.phtml

There is also a full module dir here:

  • /app/code/local//Customer/

Edit:
I need access to the users country and userid. It’s ok if country is null.

Edit:
I’ve been doing additional research, it looks like I can do something like this:
Current user in Magento?

But I haven’t tried it in code yet ….

Edit: Figured it out:

error_log(print_r(Mage::getSingleton('customer/session')->getCustomer()->getEntityId(), true));
error_log(print_r(Mage::getSingleton('customer/session')->getCustomer()->getCountry(), true));

Accessing custom variables from a .phtml in Magento

Possibly Related Posts:


 

Leave a Reply