Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Hominis06 opened this issue Sep 23, 2024 · 2 comments
Open

Comments

@Hominis06
Copy link

Hominis06 commented Sep 23, 2024

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

@xoofx
Copy link
Member

xoofx commented Sep 23, 2024

Indeed, possibly a bug. As a workaround, could you try to put the interpolation between (...)?

(Note: Too busy these days to have a look at bug fixing for this project)

@Hominis06
Copy link
Author

Yep, workaround with brackets works fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants