如何在代码中使用应用了特定magento模板在Magento中创建空白页面(外部页面)

时间:2014-10-10 00:05:15

标签: magento

不确定最好的解决方法,我正在寻找解决方案。我需要创建一个空白页面(稍后我将添加代码),并将特定主题作为设计。我在以下位置创建了自定义主题:/ app / design / frontend / indigo / mytheme /并且需要知道如何创建页面,我们可以将其命名为/test.php,并将主题应用于该页面。

到目前为止

代码是这样,但这只显示默认主题:

<?php
define('MAGENTO_ROOT', $_SERVER['DOCUMENT_ROOT']);
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
if (!file_exists($mageFilename)) {
    echo $mageFilename." was not found";
    exit;
}
require_once $mageFilename;

Mage::app()->loadArea('frontend');
$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default'); 
$layout->generateXml()->generateBlocks();

//get the loaded head and header blocks and output
$headBlock = $layout->getBlock('head');
$headerBlock = $layout->getBlock('header');
$footerBlock = $layout->getBlock('footer');

echo $headBlock->toHtml() . $headerBlock->toHtml();
?>
My content goes here
<?php
echo $footerBlock->toHtml();
?>

2 个答案:

答案 0 :(得分:1)

解决方案非常基础,您只需要设置商店ID:

Mage::app()->setCurrentStore(STORE_ID);

所以最终的代码如下:

<?php
define('MAGENTO_ROOT', $_SERVER['DOCUMENT_ROOT']);
define('STORE_ID', 15);
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
if (!file_exists($mageFilename)) {
    echo $mageFilename." was not found";
    exit;
}
require_once $mageFilename;

Mage::app()->setCurrentStore(STORE_ID);
Mage::app()->loadArea('frontend');
$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default'); 
$layout->generateXml()->generateBlocks();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php echo $layout->getBlock('head')->toHtml() ?>
</head>
<body>
<?php echo $layout->getBlock('after_body_start')->toHtml() ?>
<?php echo $layout->getBlock('global_notices')->toHtml() ?>
<?php echo $layout->getBlock('header')->toHtml() ?>
<div class="content-wrapper">
    <div class="container_12">
        <?php echo $layout->getBlock('breadcrumbs')->toHtml() ?>
        <div class="main-container col1-layout">
            <div class="grid_12 col-main">
                <?php echo $layout->getBlock('global_messages')->toHtml() ?>
                <?php echo $layout->getBlock('content')->toHtml() ?>
                My content goes here
            </div>
            <div class="clear"></div>
        </div>    
    </div>
</div>
<?php echo $layout->getBlock('footer')->toHtml() ?>
</body>
</html>

答案 1 :(得分:0)

我认为您可以从以下更清洁的解决方案中获益:https://magento.stackexchange.com/questions/154974/create-completely-empty-page-in-magento-1-9-2-4取决于您想要接近核心的程度:)

编辑-干净的完整解决方案:

创建一个新的自定义控制器(https://www.pierrefay.com/magento-training/create-a-controller-tutorial.html

class Vendor_Module_LoremController extends Mage_Core_Controller_Front_Action
{
    /**
     * Get a shop now block for specific product
     */
    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();
        // Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles()); // If you need to debug to see which layout handles are available
    }
}

在您的主题local.xml中(/app/design/frontend/[vendor]/[theme]/layout/local.xml):

<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
    <vendor_module_lorem_index>
        <remove name="header" />
        <remove name="footer" />
    </vendor_module_lorem_index>
</layout>