Home > Web Front-end > HTML Tutorial > Use template engine to render HTML interface_html/css_WEB-ITnose

Use template engine to render HTML interface_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:50:46
Original
1085 people have browsed it

Use template engine to render HTML interface

by Wu Xueying


Template engine: GRMustache

pod 'GRMustache' , '~> ; 7.3.0'


html template:

template.html

< HEAD>

{{ name }}

< ;P> {{ content }}


Call:

- ( 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;

}


Effect:



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template