簡體   English   中英

在magento中的不同phtml文件中訪問變量

[英]Accessing variable across different phtml file in magento

我想將javascript文件從magneto head.phtml文件中推遲,腳本和css由$this->getCssJsHtml(); 磁頭head.phtml文件中的函數,所以只是簡單地將輸出像

$str  =  $this->getCssJsHtml();
$css  =  substr($str, 0, strpos($str, "<script"));
$js   =  substr($str,strpos($str, "<script") );

然后我將$ js保存到注冊表

Mage::register('hs_scripts'  ,  $js); 

footer.phtml我從注冊表中調用它

echo Mage::registry("hs_scripts");

現在, 除非我啟用了磁緩存 ,並且一切正常,除非我啟用了磁緩存 ,然后打開主頁,然后說,在接下來的每一頁上,只有首頁腳本被加載,

如果我禁用緩存,一切正常,因此我需要一種存儲數據形式1 phtml文件,然后在其他文件上訪問它的方法

而是將腳本添加到已緩存的頁腳塊中,嘗試創建新塊並將其添加到before_body_end塊中。

[主題] /layout/local.xml文件:

<default>
    <reference name="before_body_end">
        <block type="core/template" name="footer.scripts" template="page/html/footer/scripts.phtml"/>
    </reference>
</default>

[theme] /template/page/html/footer/scripts.phtml文件:

echo Mage::registry('hs_scripts');

祝你好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM