Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3692600
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:16:51+00:00 2026-05-19T04:16:51+00:00

when writing a new set of .phtml & block: What is the recommanded way

  • 0

when writing a new set of .phtml & block:
What is the recommanded way to know if the block is currently on a product page ?
If it is on a product page then how do I get to the data of the currently being viewed product ?

Thanks,
Eyal

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:16:52+00:00Added an answer on May 19, 2026 at 4:16 am

    1st question) How to know that you’re on product view page.

    Your problem is not clear because you don’t say the purpose of such functionality. I interpret your question as “How can my blockknow that it’s embedded in Product View page and not in some other page?”.

    The most common way is to get layout of page and search it for standard block designed to view product. So in your block you can make following request:

    $block = $this->getLayout()
        ->getBlock('product.info');
    
    if ($block) {
        // Block exists - you're viewing product page
    }
    

    The other method is to check layout handles used to form current page layout:

    $handles = $this->->getLayout()
        ->getUpdate()
        ->getHandles();
    if (in_array('catalog_product_view', $handles)) {
        // Handle exists - you're viewing product page
    }
    

    However it’s more concrete method, it returns positive result only when viewing product page and not pages with similar designs using product view blocks. For, example Product Review page will show you same product page with minor differences but it uses its own (not ‘catalog_product_view’) handle for it. As far as you said nothing about your purpose I cannot recommend you to choose first or second method.

    Notice: you architecture can be wrong, because usually
    a) your block either doesn’t need to know where it’s embedded, so it doesn’t need not check currently viewed page
    b) or your block is used only for product view page. But in this case it’s a layout xml task to put your block only in required pages and blocks.

    2nd question) How to get current product on product view page.

    Use following code:

      $product = Mage::registry('current_product');
    

    And you’ll get the product currently viewed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When writing a new jQuery plugin is there a straightforward way of checking that
I am somewhat new to writing sql, and I know I can write a
Typically when writing new code you discover that you are missing a #include because
We perform updates of large text files by writing new records to a temp
I am writing some new code that will throw a custom exception - I
I'm writing a new daemon, which will be hosted on Debian Linux. I've found
I’m writing a new iPhone app which doesn’t depend on any of the 3.0
I am writing a new application using the Entity Framework. Where would the EF
I am writing some new SQL queries and want to check the query plans
When we are writing a new version of a library we made (in C),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.