[英]Accessing variable across different phtml file in magento
i want to defer javascript files form magneto head.phtml
file, the scripts and css are called by the $this->getCssJsHtml();
我想将javascript文件从magneto head.phtml
文件中推迟,脚本和css由$this->getCssJsHtml();
function in magneto head.phtml file so is just simple substr the output like 磁头head.phtml文件中的函数,所以只是简单地将输出像
$str = $this->getCssJsHtml();
$css = substr($str, 0, strpos($str, "<script"));
$js = substr($str,strpos($str, "<script") );
then i save the $js to registry like 然后我将$ js保存到注册表
Mage::register('hs_scripts' , $js);
and in the footer.phtml
i call it from the registry like 在footer.phtml
我从注册表中调用它
echo Mage::registry("hs_scripts");
now every thing work well unless i enable the magneto cache , and when i enable the magneto cache and then open let say homepage then, on every next page only the homepage scripts get loaded, 现在, 除非我启用了磁缓存 ,并且一切正常,除非我启用了磁缓存 ,然后打开主页,然后说,在接下来的每一页上,只有首页脚本被加载,
if i disable the cache, everything work, so i need a way to store data form 1 phtml file and then access it on other file 如果我禁用缓存,一切正常,因此我需要一种存储数据形式1 phtml文件,然后在其他文件上访问它的方法
Instead adding your scripts to footer block, which gets cached, try creating new block and adding it to before_body_end
block. 而是将脚本添加到已缓存的页脚块中,尝试创建新块并将其添加到before_body_end
块中。
[theme]/layout/local.xml file: [主题] /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 file: [theme] /template/page/html/footer/scripts.phtml文件:
echo Mage::registry('hs_scripts');
Best of luck! 祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.