Skip to content

String interpolation is not working when used in function call expression #564

@Hominis06

Description

@Hominis06

I have declared .net function

public static class ResourceService
{        
    public static string Resource(string language, string key)
    {
        if (_generalResources.TryGetValue(language, out IReadOnlyDictionary<string, string> value) && value.ContainsKey(key))
        {
            return value[key];
        }
        else
        {
            return null;
        }
    }
}

And i have custom template, that have this section to render by scriban:
"{{ $"{resource "ru-RU" $"General.{string.capitalize require_for_auto_test}"}" }}"

require_for_auto_test is a boolean variable, that comes as incoming arguments

When I try to render template with this code snippet

ScriptObject scribanObject = new ();
scribanObject.Import(arguments, null, null);
scribanObject.Import(typeof(ResourceService));

TemplateContext context = new ();
context.PushGlobal(scribanObject);

string renderResult = await scribanTemplate.RenderAsync(context);

And renderResult return not null or some other value from Resource function. Instead, renderResult returns "True". While debugging my c# code i discovered that scriban called imported function Resource without attempting to interpolate second argument (string key) of function (In C# debugger i see just "General."). After Resource function returned null, RenderAsync returns just "True" (or "False" - depends on value of require_for_auto_test variable) instead of "null". It's looks like scriban print result of string interpolation $"General.{string.capitalize require_for_auto_test}".

Expected behavior: at first, scriban interpolate string $"General.{string.capitalize require_for_auto_test}" and then calls function $"{resource "ru-RU" "General.True"}"

Current version of scriban library: 5.10.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions