how do I render an NSObject in local HTML template in iOS [closed]
I have a local html file I would like to use as a template to print some different NSObjects, is there a way to r开发者_高级运维ender this without having to do a bunch of stringByReplacingOccuranceOfString methods?
Looking for something I would do in MVC on a web site:
HTML Template:
<html>
<head>
</head>
<body>
<h1>Manufacturer</h1>
<p>
##Manufacturer.ManufacturerName##
</p>
</body>
</html>
And would call some function passing in the Manufacturer object and get an NSString back of that template with the object property values substituted in place of my placeholder values.
You can do something like this:
NSString *html = [NSString stringWithFormat:@"<html>
<head>
</head>
<body>
<h1>Manufacturer</h1>
<p>
%@
</p>
</body>
</html>", Manufacturer.ManufaacturerName];
[webView loadHTMLString:html baseURL:[NSURL URLWithString:@"some random page"]]; //I'm not entirely sure what the baseURL is used for
Look at the always-brilliant Matt Gemmell's MGTemplateEngine.
https://github.com/groue/GRMustache is a nice alternative to Matt Gemmel's MGTemplateEngine that works on both iOS and MacOS out of the box, and has copious documentation.
精彩评论