Closed Vfleitao closed 1 month ago
Looking a bit deeper into the ArgumentsParser, I wonder if something like this would not make sense so that if the argument ends up being a an UndefinedBindingResult we return the default value or throw an exception?
public static List<object?> Parse(IHandlebars context, ParameterInfo[] parameters, Arguments arguments)
{
var result = new List<object?>();
for (int i = 0; i < parameters.Length; i++)
{
if (parameters[i].IsParam())
{
result.Add(arguments.Skip(i).ToArray());
}
else if (i < arguments.Length)
{
result.Add(arguments[i]);
}
}
return result.Select(argument => Parse(context, argument)).ToList();
}
public static object? Parse(IHandlebars context, object? argument, bool convertObjectArrayToStringList = false)
{
if (argument is UndefinedBindingResult valueAsUndefinedBindingResult)
{
if (TryParseUndefinedBindingResult(valueAsUndefinedBindingResult, out var parsedAsObjectList) && convertObjectArrayToStringList)
{
return parsedAsObjectList.Cast<string?>().ToList();
}
if(context.Configuration.ThrowOnUnresolvedBindingExpression)
{
throw new HandlebarsRuntimeException($"The value '{valueAsUndefinedBindingResult.Value}' cannot be converted to a valid type.");
}
return valueAsUndefinedBindingResult.Value;
}
return argument;
}
I guess the viewData is null or does not have a property named page?
What is rendered for this?
<a href="/" class="plain text-black {{viewData.page}}">Home</a>
I guess the viewData is null or does not have a property named page? What is rendered for this?
<a href="/" class="plain text-black {{viewData.page}}">Home</a>
In my case, the viewData is literally just set with the null value.
It renders
<a href="/" class="plain text-black viewData.page">Home</a>
since my UnresolvedBindingFormatter is set to "{0}"
95
now this is a quick fix. Thank you very much @StefH
Heya
I have a small template that contains lines like this
When I use the ThrowOnUnresolvedBindingExpression = false HandleBarsConfiguration, the String.Equal still throws an exception with
if the viewData.page is an UndefinedBindingResult.
Just doing this works as expected
Is this an expected behaviour or am I missing some configuration on the Helpers?