[英]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.