Variables (`@something`) in layouts cannot be bound
Closed this issue · 1 comments
Describe the bug
Using a variable expression (@something
) does not work in a layout view, while it does in the ‘child’ view.
When providing the value for a variable in the data
parameter, it should be possible to bind it in a layout view. Instead, depending on whether ThrowOnUnresolvedBindingExpression
is true, it will throw an exception (HandlebarsUndefinedBindingException: something is undefined
) or simply bind to an empty string.
Expected behavior:
When I use a variable expression (@something
) in a layout view, and I provide that value in the data
parameter, I expect it to be bound correctly.
Test to reproduce
[Fact]
public void CanRenderVariablesInCasperLayout()
{
var fs = new DiskFileSystem();
var handlebars = Handlebars.Create(new HandlebarsConfiguration()
{
FileSystem = fs
});
AddHelpers(handlebars);
var renderView = handlebars.CompileView("ViewEngine/Casper-master/index.hbs");
var output = renderView(
new
{
posts = new[]
{
new
{
title = "My Post Title",
image = "/someimage.png",
post_class = "somepostclass"
}
}
},
new
{
blog = new
{
url = "http://someblog.com",
title = "This is the blog title"
}
}
);
var cq = CsQuery.CQ.CreateDocument(output);
Assert.Equal("This is the blog title", cq["section.copyright a"].Text());
}
Other related info
Editing the template so the expression is no longer a variable and providing the data in the context
parameter does work.
Related to #97 as might become obsolete if view engine redesign comes first.