5

I've been building a module in which I need to know if a page has a unique layout.

My first thought was to get the list of layout handles and hash them. This works well for the most part, but doesn't take into account database layout updates.

My second thought was to hash the entire layout updates and use that. In principle, this works, but I think perhaps I am using the wrong function:

md5(Mage::app()->getLayout()->getUpdate()->asString());

This seems to get the same thing on every request. How do I just get the updates applied on a specific request? Is there a convenient function for that?

Or, is there a way to just get db updates? Something like

md5(implode($update->getHandles()) . $update->getAllDbLayoutUpdates());

would also be swell.

Looking at it from a different angle, is there such a method created already? Have I been looking at it all wrong?

4
  • I'm not sure without checking out the core, but I think you might want to try using getLayout()->getOutput() as that should just get the blocks to be output for a specific layout.
    – pspahn
    Sep 5, 2014 at 1:01
  • I do not know for what you want to use it, but if it is for caching stuff, you may want to have a look at cache tags.
    – Simon
    Sep 5, 2014 at 6:04
  • I assume you need to check this in an observer. If I'm right, what event are you observing?
    – Marius
    Sep 9, 2014 at 9:47
  • @Marius Right now it's controller_front_send_response_before, but I'd accept any event that gave me the complete html output Sep 9, 2014 at 15:37

1 Answer 1

2

Not sure if this is what you need, but It seams I get a correct result with Mage::app()->getLayout()->getXmlString().
I tried for homepage and it even shows the value I add in the Layout Update XML field of the page.
I tried for a few other pages and it seams to get me the correct xml.
I also added a widget instance somewhere on the left column and it appears in the result.
So it works with the db layout updates.

4
  • Fantastic, thank you. I'll take a look. Can you think of anything else that determines the html content of a page? The layout updates, the handles, and the current theme/design package. I suppose the store view, as well. Am I missing anything? Sep 10, 2014 at 8:20
  • The state of the customer. Logged in or not. That's the first thing that comes into my mind. And on the same line, some block contents might depend on the session. For example the recently viewed products or the last ordered items, or the wishlist.
    – Marius
    Sep 10, 2014 at 8:24
  • That's a layout handle too, though. Sep 10, 2014 at 18:16
  • I'm writing a module to leverage uncss (giakki/uncss) with Magento. I need to determine which css selectors are used on a page. I'm not too worried about recent products, because the html won't change much. I don't want to have to go through sitemap.xml to do this, though. Sep 10, 2014 at 18:29

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.