好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

使用模板引擎渲染HTML界面_html/css_WEB-ITnose

使用模板引擎渲染HTML界面

by 伍雪颖


模板引擎:GRMustache

pod 'GRMustache' , '~> 7.3.0'


html模板:

template.html

{{ name }}

{{ content }}


调用:

- ( void )viewDidLoad {

[ super viewDidLoad ];
NSString *path = [[ NSBundle mainBundle ] bundlePath ];
NSURL *baseUrl = [ NSURL fileURLWithPath :path];
NSString *htmlString = [ self demoFormatWithName : @"wuxueying" value : @"hello" ];
[ self . webView loadHTMLString :htmlString baseURL :baseUrl];
}

- ( NSString *)demoFormatWithName:( NSString *)name value:( NSString *)value {
NSString *fileName = @"template.html" ;
NSString *path = [[[ NSBundle mainBundle ] bundlePath ] stringByAppendingPathComponent :fileName];
NSString *template = [ NSString stringWithContentsOfFile :path encoding : NSUTF8StringEncoding error : nil ];
NSDictionary *renderObject = @{ @"name" :name, @"content" :value } ;
NSString *content = [ GRMustacheTemplate renderObject :renderObject fromString :template error : nil ];
return content;

}


效果:

查看更多关于使用模板引擎渲染HTML界面_html/css_WEB-ITnose的详细内容...

  阅读:29次