在页面上加载在ajax中显示Magento静态块

时间:2013-05-17 15:40:26

标签: ajax magento

我正在使用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)在view.phtml中我添加了一个链接

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

灯箱正在工作,但是没有调用静态块...仍在弄清楚如何调用静态框..

1 个答案:

答案 0 :(得分:0)

我使用以下步骤成功调用了包含静态块的弹出窗口。

http://jsfiddle.net/5USUu/

基本上我们需要:

  1. 添加.js和.css文件 - 我正在使用colorbox
  2. 定义功能
  3. 调用函数
  4. 1)在标题

    中添加以下脚本
    <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-->