• JEECMS自定义标签开发步骤


    JEECMS自带的只有[@cms_advertising]标签,并且官方没有给文档,用法:

    [@cms_advertising id='3'] 
                <img src="${(tag_bean.attr.image_url)!?html}" width="${(tag_bean.attr.image_width)!?html}" height="${(tag_bean.attr.image_height)!?html}" /> 
     [/@cms_advertising]

    这个是根据广告ID的来调用单独的一条广告,首页幻灯片一般都有多张,不能满足需求。

    其实jeecms也有另一个js调用已经实现了的,但是不能生成到html中,用户体验不好。(com.jeecms.cms.action.front.AdvertisingAct类,<script src="/ad.jspx"  ……)

    回到正题,自己增加一个标签,名字叫做:cms_advertising_space

    步骤一:

    jeecms-context.xml中增加一个bean:

    1

    2

    <!-- 新增按照广告牌取所有广告标签 -->

    <bean id="cms_advertising_space" class="com.jeecms.cms.action.directive.CmsAdvertisingSpaceDirective"/>

    步骤二:

    jeecms.properties添加cms_advertising_space标签

    1

    directive.cms_advertising_space=cms_advertising_space

      

    步骤三:

    新增一个类:CmsAdvertisingSpaceDirective

    复制代码

    1.  
      package com.jeecms.cms.action.directive;
    2.  
       
    3.  
      import static com.jeecms.common.web.freemarker.DirectiveUtils.OUT_BEAN;
    4.  
      import static freemarker.template.ObjectWrapper.DEFAULT_WRAPPER;
    5.  
       
    6.  
      import java.io.IOException;
    7.  
      import java.util.HashMap;
    8.  
      import java.util.List;
    9.  
      import java.util.Map;
    10.  
       
    11.  
      import org.springframework.beans.factory.annotation.Autowired;
    12.  
      import static com.jeecms.common.web.freemarker.DirectiveUtils.OUT_LIST;
    13.  
      import com.jeecms.cms.entity.assist.CmsAdvertising;
    14.  
      import com.jeecms.cms.entity.assist.CmsAdvertisingSpace;
    15.  
      import com.jeecms.cms.manager.assist.CmsAdvertisingMng;
    16.  
      import com.jeecms.cms.manager.assist.CmsAdvertisingSpaceMng;
    17.  
      import com.jeecms.common.web.freemarker.DirectiveUtils;
    18.  
       
    19.  
      import freemarker.core.Environment;
    20.  
      import freemarker.template.TemplateDirectiveBody;
    21.  
      import freemarker.template.TemplateDirectiveModel;
    22.  
      import freemarker.template.TemplateException;
    23.  
      import freemarker.template.TemplateModel;
    24.  
       
    25.  
      /**
    26.  
      * 广告对象标签
    27.  
      */
    28.  
      public class CmsAdvertisingSpaceDirective implements TemplateDirectiveModel {
    29.  
      /**
    30.  
      * 输入参数,广告ID。
    31.  
      */
    32.  
      public static final String PARAM_ID = "id";
    33.  
       
    34.  
       
    35.  
      @SuppressWarnings("unchecked")
    36.  
      public void execute(Environment env, Map params, TemplateModel[] loopVars,
    37.  
      TemplateDirectiveBody body) throws TemplateException, IOException {
    38.  
      Integer id = DirectiveUtils.getInt(PARAM_ID, params);
    39.  
      List<CmsAdvertising> ads = null;
    40.  
      CmsAdvertisingSpace adspace;
    41.  
      if (id != null) {
    42.  
       
    43.  
      //ad = cmsAdvertisingMng.findById(id);
    44.  
      ads= cmsAdvertisingMng.getList(id, true);
    45.  
      }
    46.  
      Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(
    47.  
      params);
    48.  
      if (ads!=null){
    49.  
      paramWrap.put(OUT_LIST, DEFAULT_WRAPPER.wrap(ads));
    50.  
      }
    51.  
       
    52.  
      Map<String, TemplateModel> origMap = DirectiveUtils
    53.  
      .addParamsToVariable(env, paramWrap);
    54.  
      body.render(env.getOut());
    55.  
      DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);
    56.  
      }
    57.  
       
    58.  
      @Autowired
    59.  
      private CmsAdvertisingMng cmsAdvertisingMng;
    60.  
      @Autowired
    61.  
      private CmsAdvertisingSpaceMng cmsAdvertisingSpaceMng;
    62.  
      }

    复制代码

    标签写法:

    1

    2

    3

    4

    5

    6

    [@cms_advertising_space id='7']

    [#list tag_list as c]

    <img src="${(c.attr.image_url)!?html}" width="${(c.attr.image_width)!?html}" height="${(c.attr.image_height)!?html}" />

    [/#list]   

     [/@cms_advertising_space]

      生成代码:

  • 相关阅读:
    ipa在线下载安装(itms-services)
    linux环境下无文件执行elf
    Linux Running State Process ".so"、"code" Injection Technology
    VS2013本地C++单元测试框架
    vs的环境变量
    利用rundll32执行程序的函数执行程序
    动态so注入
    ELF运行时注入
    MailKit系列之转发电子邮件
    WPF实战之一 桌面消息框(右下角消息弹出框)
  • 原文地址:https://www.cnblogs.com/Jeely/p/11196023.html
Copyright © 2020-2023  润新知