使用模板引擎渲染HTML界面
来源:互联网 发布:怎么配置java开发环境 编辑:程序博客网 时间:2024/04/29 07:16
使用模板引擎渲染HTML界面
by 伍雪颖
模板引擎:GRMustache
pod 'GRMustache','~> 7.3.0'
html模板:
template.html
<HTML>
<HEAD>
</HEAD>
<BODY>
<H1> {{ name }}</H1>
<P> {{ content }}</P>
</BODY>
</HTML>
调用:
- (void)viewDidLoad {
[superviewDidLoad];
NSString *path = [[NSBundlemainBundle]bundlePath];
NSURL *baseUrl = [NSURLfileURLWithPath:path];
NSString *htmlString = [selfdemoFormatWithName:@"wuxueying"value:@"hello"];
[self.webViewloadHTMLString:htmlStringbaseURL:baseUrl];
}
- (NSString *)demoFormatWithName:(NSString *)name value:(NSString *)value {
NSString *fileName =@"template.html";
NSString *path = [[[NSBundlemainBundle]bundlePath]stringByAppendingPathComponent:fileName];
NSString *template = [NSStringstringWithContentsOfFile:pathencoding:NSUTF8StringEncodingerror:nil];
NSDictionary *renderObject =@{@"name":name,@"content":value};
NSString *content = [GRMustacheTemplaterenderObject:renderObjectfromString:templateerror:nil];
return content;
NSString *path = [[NSBundlemainBundle]bundlePath];
NSURL *baseUrl = [NSURLfileURLWithPath:path];
NSString *htmlString = [selfdemoFormatWithName:@"wuxueying"value:@"hello"];
[self.webViewloadHTMLString:htmlStringbaseURL:baseUrl];
}
- (NSString *)demoFormatWithName:(NSString *)name value:(NSString *)value {
NSString *fileName =@"template.html";
NSString *path = [[[NSBundlemainBundle]bundlePath]stringByAppendingPathComponent:fileName];
NSString *template = [NSStringstringWithContentsOfFile:pathencoding:NSUTF8StringEncodingerror:nil];
NSDictionary *renderObject =@{@"name":name,@"content":value};
NSString *content = [GRMustacheTemplaterenderObject:renderObjectfromString:templateerror:nil];
return content;
}
效果:
1 0
- 使用模板引擎渲染HTML界面
- UIWebView---iOS中使用模板引擎渲染HTML界面
- iOS中使用模板引擎渲染HTML界面
- UIWebView---iOS中使用模板引擎渲染HTML界面
- HTML模板渲染引擎Hogan
- html模板渲染引擎有什么作用
- Outlook HTML渲染引擎
- 【Web】artTemplate模板引擎:编译(生成渲染函数)+渲染(生成HTML串) 模板:基于JS的语法(JS+自定义)+HTML
- html渲染模板Hogan
- ios中使用模版引擎渲染HTML页面
- GRMustache的使用(HTML模板渲染工具)For iOS
- HTML模板引擎
- flask使用渲染模板
- c#使用 VTemplate模板引擎制作html报表
- 使用模板引擎jade生成邮件HTML正文
- node.js 使用ejs模板引擎时后缀换成.html
- Jtemplete/客户端模板的脚本渲染引擎
- 模板引擎中的模板获取,模板渲染 原理
- java中的字面量
- Java中整数与字符串的相互转化
- Android使用Intent传递List或者对象
- K-近邻算法(KNN)
- 2014国家反腐案件
- 使用模板引擎渲染HTML界面
- Oracle Gateway11g R2访问异构数据库(MSSQL)配置文档--图文详细介绍
- MATLAB图像处理_同态滤波
- Failed to load Main-Class manifest attribute from
- 学习 操作系统 会遇到的一些问题
- 管理神话之八:我还能做大量的技术工作
- 陌陌架构分享
- 使用最新 ALSA 驱动解决 UBUNTU LINUX INTEL 集成声卡问题
- CDH5.X安装配置kerberos认证过程