1

Looking to create HTML elements as part of a Dart client side application.

There are multiple approaches to doing this.

Ideally the HTML template to create new elements would live with the rest of the HTML and not inline with Dart code.

Are there any options for separating HTML templates and Dart code?

Background

Common approaches to creating HTML content on the fly:

  1. Create in Code, as explained here: How to create an HTML link in Dart?

  2. Input as a String from Code, also explained in the above link.

  3. Use Polymer, which does solve this, although appears to require boilerplate. Polymer would appear to be overkill for use cases which don't require custom elements, data binding and other features.

There was at one point the DART HTML Template Library, work now stopped: http://blog.sethladd.com/2012/03/first-look-at-darts-html-template.html

There is also the HTML5 'template' element. The HTML5 'template' tag has limited (50%) support at caniuse.com which currently limits it's applicability.

1 Answer 1

2

You can use the template_binding package which is what Polymer uses for its templates. You might also want to use the polymer_expressions package for a more powerful expression syntax.

The important bit is that you don't need all of Polymer to use those. Check out the polymer_expressions tests for examples of using template_binding without the rest of Polymer.

Sign up to request clarification or add additional context in comments.

1 Comment

The tests for polymer_expressions are at /dart/pkg/polymer_expressions/test/, viewable on the web at googlesource.com or at GitHub

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.