显示包含html标签的属性

时间:2012-07-12 11:13:21

标签: ember.js handlebars.js

我有一个包含html标签的余烬属性(<br /><strong><p><span>以及类似内容。

我怎么能告诉灰烬不要逃避这个文字?是否有来自ember的默认Handlebars助手,还是需要我自己编写?

3 个答案:

答案 0 :(得分:85)

来自http://handlebarsjs.com/

  

Handlebars HTML-escapes {{expression}}返回的值       如果您不希望Handlebars转义值,请使用“triple-stash”。

     

{{{expression}}}

答案 1 :(得分:16)

Ember.js中,您可以通过添加到htmlSafe原型的String方法执行此操作,请参阅http://jsfiddle.net/pangratz666/jNAQ6/

<强>车把

<script type="text/x-handlebars" >
    {{App.html}} - {{App.unescaped}}
</script>​

<强>的JavaScript

App = Ember.Application.create({
    html: '<b>bold text</b>',
    unescaped: function(){
        return this.get('html').htmlSafe();
    }.property('html')
});​

答案 2 :(得分:3)

Ember 2.x,使用JavaScript

要使用Ember模板对字符串进行非转义并输出,您可以使用- (void)CurrentLocationIdentifier { //---- For getting current gps location // locationManager = [CLLocationManager new]; locationManager=[[CLLocationManager alloc]init]; locationManager.delegate = self; locationManager.distanceFilter = kCLDistanceFilterNone; locationManager.desiredAccuracy = kCLLocationAccuracyBest; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) [locationManager requestWhenInUseAuthorization]; [locationManager startUpdatingLocation]; } -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { if(kCLAuthorizationStatusDenied) { } } - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { //currentLocation = [locations objectAtIndex:0]; currentLocation=[locations lastObject]; NSLog(@"location:%@",currentLocation); [locationManager stopUpdatingLocation]; //[locationManager startUpdatingLocation]; geocoder = [[CLGeocoder alloc] init] ; [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) { if (!(error)) { placemark = [placemarks objectAtIndex:0]; NSLog(@"\nCurrent Location Detected\n"); NSString *Country = [[NSString alloc]initWithString:placemark.ISOcountryCode]; NSString *state =[[NSString alloc]initWithString:placemark.administrativeArea]; //NSString *state =placemark.administrativeArea; NSLog(@"%@",Country); NSLog(@"administrativeArea>>%@",state); self.stateLabel.text=state; //[locationManager stopUpdatingLocation]; [[NSUserDefaults standardUserDefaults]setValue:Country forKey:@"countryISOCode"]; } else { } }]; [locationManager stopUpdatingLocation]; } 帮助程序。

htmlSafe

Handlebars模板引擎不会对返回的字符串进行HTML转义。

http://emberjs.com/api/classes/Ember.String.html#method_htmlSafe

仅使用把手

或者,您可以将原始HTML传递给Handlebars模板,并使用三个括号获取原始HTML输出

车把内部模板

Ember.String.htmlSafe('<div>someString</div>')