diff --git a/spec/basicsSpec.coffee b/spec/basicsSpec.coffee
index 4876c611..ad929f76 100644
--- a/spec/basicsSpec.coffee
+++ b/spec/basicsSpec.coffee
@@ -62,6 +62,14 @@ describe "Transparency", ->
template.render data
expect(template).toBeEqual expected
+ it "should accept context as a string", ->
+ template = '
diff --git a/spec/basicsSpec.js b/spec/basicsSpec.js
index 353c17a5..7d22b11f 100644
--- a/spec/basicsSpec.js
+++ b/spec/basicsSpec.js
@@ -38,6 +38,17 @@
template.render(data);
return expect(template).toBeEqual(expected);
});
+ it("should accept context as a string", function() {
+ var data, expected, template;
+
+ template = '
';
+ data = {
+ hello: 'Hello'
+ };
+ expected = $('
');
+ template = $(window.Transparency.render(template, data));
+ return expect(template).toBeEqual(expected);
+ });
it("should match model keys to template by element id, class, name attribute and data-bind attribute", function() {
var data, expected, template;
diff --git a/src/transparency.coffee b/src/transparency.coffee
index 530aff23..bccf5d4d 100644
--- a/src/transparency.coffee
+++ b/src/transparency.coffee
@@ -42,6 +42,12 @@ Transparency.render = (context, models = [], directives = {}, options = {}) ->
return unless context
models = [models] unless _.isArray models
+ # If context was passed in as an HTML string, then convert it to a div element with innHTML as passed in HTML string.
+ if typeof context == 'string'
+ _html_string = context
+ context = document.createElement('div')
+ context.innerHTML = _html_string
+
# Context element, state and functionality is wrapped to `Context` object. Get it, or create a new
# if it doesn't exist yet.
context = helpers.data(context).context ||= new Context(context, Transparency)