2

I am working in a marketplace extension and I need to use some blocks from adminhtml(backend blocks), Actually I want to use all blocks in handle to be used in the frontend by sellers to add their new products . I try to update current layout by :

 $this->loadLayout('adminhtml_catalog_product_new');

but It doesn't work.

2

As far as I know, this layout handle will not be available during a frontend request, because Magento does not load layout XML out of app/design/adminhtml/*. See Mage_Core_Model_Layout_Update::getFileLayoutUpdatesXml:

...
$filename = $design->getLayoutFilename($file, array(
    '_area'    => $area,
    '_package' => $package,
    '_theme'   => $theme
));
...

So the layout update model consults the design package by asking it to locate a layout file. And one of the requirements is to specify the area (frontend|adminhtml). So early in the routing process we omit one of the two areas -- adminhtml handles will not be available on a frontend request.

An alternative approach would be to write your own layout update and add it to the frontend:

# File: app/code/local/Yournamespace/Yourmodule/etc/config.xml
...
<frontend>
    ...
    <layout>
        <updates>
            <yourmodule>
                <file>yourmodule.xml</file>
            </yourmodule>
        </updates>
    </layout>
    ...
</frontend>

And in that update, re-create the layout updates from your desired admin handle:

# File: app/design/frontend/[package]/[theme]/layout/yourmodule.xml
...
<yourmodule_custom_handle>
    <update handle="editor"/>
    <reference name="content">
        <block type="adminhtml/catalog_product_edit" name="product_edit"></block>
    </reference>
    <reference name="left">
        <block type="adminhtml/catalog_product_edit_tabs" name="product_tabs"></block>
    </reference>
    <reference name="js">
        <block type="adminhtml/catalog_product_edit_js" template="catalog/product/js.phtml" name="catalog_product_js"></block>
        <block type="core/template" template="catalog/wysiwyg/js.phtml"/>
    </reference>
</yourmodule_custom_handle>
...

Then you can call:

$this->loadLayout('yourmodule_custom_handle');

From your controller or wherever you're working. Just note that this probably won't work as expected, because of how many admin-specific dependencies there are to make the admin area work. If values are expected to be in the registry, they likely won't be set on the frontend. URLs might not resolve as you would expect.

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.