本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7591312
建立时间:2006年5月29日




[FreeMarker]使用freemarker给cms生成静态html
软件技术

lhwork 发表于 2006/12/15 12:20:35

作为CMS内容发布来说,将要显示的内容html化无疑是一个很基本的要求,这样可以提高整个系统的效率。考虑一个内容节点Content,其中节点有个pagecontent的属性,这个属性用来存储用户在后台输入的内容,内容+模板=显示,这里是:内容+模板-->显示静态html内容用FCK来编辑,模板也同样用FCK编辑,这里用freemarker无疑是一个好的选择。这里是个最简单的例子。首先定义一个最简单的模板content.ftl500)this.width=500'><html>500)this.width=500'>500)this.width=500'>$500)this.width=500'>{content}500)this.width=500'></html>然后就是把内容填充进去:500)this.width=500'> Configuration cfg = new Configuration();500)this.width=500'> //模板存储的目录500)this.width=500'> cfg.setDirectoryForTemplateLoading(Path.getTemplateDirectory());500)this.width=500'> //默认500)this.width=500'> cfg.setObjectWrapper(new DefaultObjectWrapper());500)this.width=500'>//填充数据        500)this.width=500'>Map root = new HashMap();500)this.width=500'>root.put("content", c.getPageContent());500)this.width=500'>     Template temp = cfg.getTemplate("content.ftl");500)this.width=500'>//发布日期500)this.width=500'>String date=c.getActivedate();500)this.width=500'>String filename = c.getId()+".html";500)this.width=500'>//创建目录500)this.width=500'>Path.createFold(Path.getWebCmsHtmlDirPath(),date);500)this.width=500'>Writer out = new OutputStreamWriter(new FileOutputStream(Path.getWebCmsHtmlDirPath()+"/"+date+"/"+filename));500)this.width=500'>temp.process(root, out);500)this.width=500'>out.flush();其实就是这么简单!对html的管理就很容易了,基本的FILE操作


阅读全文(4081) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.273 second(s), page refreshed 144770060 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号