2014-10-10 12 views
-2

不確定最佳方式來解決此問題並正在尋找解決方案。我有要求創建一個空白頁面(以後我將添加代碼)與特定的主題作爲設計。我在/ app/design/frontend/indigo/mytheme /中創建了自定義主題,並且需要知道如何創建一個頁面,可以將其稱爲/test.php,並將主題應用於該頁面。如何在應用了特定的magento模板的代碼中創建Magento中的空白頁(外部頁面)

代碼到目前爲止是這樣的,但是這隻能說明默認主題:

<?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(); 
?> 
+0

有人可以解釋爲什麼這是被投票嗎?我認爲這是一個合理的問題,我無法在SO上找到答案。 – 2014-10-13 00:21:57

回答

0

的解決方案是很基本的,你只需要設置店鋪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>