在PageLoad显示Magento静态块在ajax



我使用的是Magento 1.7,这是一个新版本。

我想达到的目标:在网站的页面加载中,显示时事通讯模板块

{{block type="newsletter/subscribe" template="newsletter/subscribe.phtml"}}

作为Magento中的一个弹出窗口,其中cookie将在给定的时间段后过期,例如:1周。

网上的答案要么不具体,要么不够详细,因为我对剧本的了解并不广泛。

我试过了:

尝试添加灯箱:

1)添加Lightbox CSS &JS

    <script type="text/javascript" src="<?php echo $this->getJsUrl('lightbox/lightbox.js'); ?>"></script>
<link rel="stylesheet" type="text/css" href="<?php echo $this->getJsUrl('lightbox/lightbox.css'); ?>" media="screen"/>

2) In view。我添加了一个链接

<a href="<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('measurement')->toHtml() ?>" rel="lightbox">Size chart</a>

灯箱正在工作,但是静态块没有被调用…还在想怎么调用静态盒子…

我已经使用下面的步骤成功调用了一个包含静态块的弹出窗口。

http://jsfiddle.net/5USUu/

基本上我们需要:

  1. 添加。js和。css文件-我使用colorbox
  2. 定义函数
  3. 调用函数

1)在header

中添加以下脚本
<link rel="stylesheet" type="text/css" href="<?php echo $this->getJSUrl('pop/colorbox.css'); ?>" media="screen"/>
<link rel="stylesheet"  type="text/css" href="<?php echo $this->getJSUrl('pop/popup.css'); ?>" />
<script language="javascript" src="<?php echo $this->getJSUrl('pop/colorbox.js'); ?>"></script>
<script>
jQuery(document).ready(function (){
 if (document.cookie.indexOf('visited=true') == -1){
      var fifteenDays = 1000*60*60*24*15; 
      var expires = new Date((new Date()).valueOf() + fifteenDays);
      document.cookie = "visited=true;expires=" + expires.toUTCString(); 
      jQuery.colorbox({width:"580px", inline:true, href:"#subscribe_popup"});
      }
      jQuery(".open_popup").colorbox({width:"580px", inline:true, href:"#subscribe_popup"});
      });
</script>

2)添加这个链接到你的弹出窗口的html

<a href="#" class="open_popup">Click here to open the popup</a>
3)添加包含静态块标识符的html
<div style='display:none'>
<div id='subscribe_popup' style='padding:10px;'> 
<!-- BEGIN #subs-container --> 
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('subscribe')->toHtml() ?>
<div id="subs-container" class="clearfix"> </div>
</div>
</div>
<!-- END subscribe popup--> 

最新更新