How to universally set MacroResolver to use the current page's culture

Rory Aherne asked on May 8, 2025 17:25

My admin site is in English and my presentation site is multi lingual (german and english).

When I check on my presentation code for the german site LocalizationContext.CurrentCulture.CultureCode gives me "de-DE" as expected.

However, when I go to resolve a macro from content entered in the admin UI, I have to do this or the EvaluationContext in my custom macro methods has the CultureInfo from the UI (english)

@{
    var macroSettings = new MacroSettings
    {
        Culture = "de-de",
    };
}
@Html.Raw(MacroResolver.Resolve(Model.Content2, macroSettings))

Is there something I'm missing to not have to do this all the time? I'm on K13 core on the latest hotfix

Correct Answer

vasu yerramsetti answered on July 9, 2025 08:08

Try this option - To avoid repeating new MacroSettings { Culture = ... } everywhere, write a utility method:

public static class MacroHelper
{
    public static string ResolveWithCurrentCulture(string content)
    {
        var settings = new MacroSettings
        {
            Culture = LocalizationContext.CurrentCulture.CultureCode
        };

        return MacroResolver.Resolve(content, settings);
    }
}

Call in Razor:

@Html.Raw(MacroHelper.ResolveWithCurrentCulture(Model.Content2))

1 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.