0

There is a new DOM based template engine called soma-template there I can do this:

var tempDiv = document.createElement("div");

var str = "<div data-repeat='item in items'><div>{{$index}} - {{greet}} {{item.name}}!</div> </div>";

var template = soma.template.create(str,tempDiv );

template.scope.greet = "Hello";

template.scope.items = [
     { "name": "John" },
     { "name": "David" },
     { "name": "Mike" }];

template.render();

var finalHtmlStr = newDiv.innerHTML;

To retrieve the processed html string.

I tried achieving a similar result with using Angularjs (Is it possible to compile angular template to final html string?) but only managed to do it using a hidden element in the page.

Then I would have to wait for angular to render that elemente and retrieve its innerHTML.

I used the $viewContentLoaded event but that not very versatile.

Althought soma-template is great it is very young and lacks some futures I need.

Is the any way to put together a render() method like soma-template's using angular as the engine?

Thanks

Community
  • 1
  • 1
RuiFortes
  • 183
  • 4
  • 13
  • 1
    The angular compile and link phases act similarly. Why not just use angular as it is meant to be used? – Davin Tryon Oct 17 '13 at 21:21
  • I want to do mail merge templating, to edit template in ckeditor and also edit the template results in that editor. Using EJS is not so good because although you can edit the source html it wont show nothing in text mode. Dom templating is better – RuiFortes Oct 17 '13 at 21:26
  • I don't think angular is the tool you are looking for. AFAIK, there isn't a templating service that will simply output the html. – Davin Tryon Oct 17 '13 at 21:37
  • the above code does althought through a temporaty dom element. would be nice to have some kind of shortcut method like that. – RuiFortes Oct 17 '13 at 22:51

0 Answers0