Mustache Template usage in Dart

Issue

Fairly recent to web programming and all apologies for asking a basic question.

In the test.dart file, a template is created and populated as below

import 'dart:html';
// IMPORT MUSTACHE FOR TEMPLATES
import 'package:mustache/mustache.dart' as mustache;

function loadData()
{
 // some script .....
  output = template.renderString({
 'data_cell': [
     {'event_title': TitleOne,'event_desc' : Desc},]});
 }

In the test.html file, how can I insert the “output” in the below “data_cell” div.

<body>
<p id="text">Application</p>
<div class="row">
   <div class="data_cell">
        <!-- HOW TO INSERT "output" generated from DART script here" -->
   </div>
</body>

Solution

querySelector('div.data_cell').appendHtml(output);

or

var nodeValidator = new NodeValidatorBuilder()
    ..allowHtml5()                            // according to your requirements
    ..allowElement('a', attributes: ['href']) // - " -
    ..allowElement('img', attributes: ['src']); // - " -
querySelector('div.data_cell').append(new Element.html(output, validator: nodeValidator);

Answered By – Günter Zöchbauer

Answer Checked By – Clifford M. (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *