diff --git a/src/ManiaTemplates/Lib/MtTransformer.cs b/src/ManiaTemplates/Lib/MtTransformer.cs index 20c6d96..99c951d 100644 --- a/src/ManiaTemplates/Lib/MtTransformer.cs +++ b/src/ManiaTemplates/Lib/MtTransformer.cs @@ -441,7 +441,7 @@ MtComponent rootComponent { _renderMethods.Add( renderMethodName, - CreateComponentRenderMethod(component, renderMethodName, componentBody) + CreateComponentRenderMethod(component, renderMethodName, componentBody, currentContext) ); } @@ -450,6 +450,12 @@ MtComponent rootComponent //Create available arguments var renderArguments = new List(); + + //Add local variables to component render method call + foreach (var localVariableName in currentContext.Keys) + { + renderArguments.Add($"{localVariableName}: {localVariableName}"); + } //Attach attributes to render method call foreach (var (attributeName, attributeValue) in attributeList) @@ -489,7 +495,7 @@ MtComponent rootComponent var slotArguments = new HashSet(); - //Add local variables + //Add local variables to slot render call foreach (var localVariableName in currentContext.Keys) { slotArguments.Add($"{localVariableName}: {localVariableName}"); @@ -539,7 +545,7 @@ MtComponent rootComponent /// /// Creates the method which renders the contents of a component. /// - private string CreateComponentRenderMethod(MtComponent component, string renderMethodName, string componentBody) + private string CreateComponentRenderMethod(MtComponent component, string renderMethodName, string componentBody, MtDataContext currentContext) { var renderMethod = new StringBuilder(_maniaTemplateLanguage.FeatureBlockStart()) .Append("private void ") @@ -548,6 +554,12 @@ private string CreateComponentRenderMethod(MtComponent component, string renderM //open method arguments var arguments = new List(); + + //Add local variables to component render method call + foreach (var (localVariableName, localVariableType) in currentContext) + { + arguments.Add($"{localVariableType} {localVariableName}"); + } //add slot render methods AppendSlotRenderArgumentsToList(arguments, component);