private static string EvalComponentExpression(ExpressionParser parser, TemplateToken token, TemplateParserContext context) { TemplateToken.ParameterizedExpression pExpr = token.ExtractParameters(); string componentName = pExpr.MainExpression; if (pExpr.MainExpression.StartsWith("(") && pExpr.MainExpression.EndsWith(")")) { componentName = parser.Evaluate <string>(pExpr.MainExpression, context, token.TokenPosition); } TemplateParserContext newContext = (TemplateParserContext)context.CreateLocal(); foreach (string varName in pExpr.Parameters.Keys) { newContext.SetLocal(varName, parser.Evaluate(pExpr.Parameters[varName], context)); } ControllerAction viewComponent = WebAppHelper.GetViewComponent(componentName); if (viewComponent == null) { throw new TemplateRenderingException("View component " + componentName + " not found", token.TokenPosition); } try { return(WebAppHelper.RunViewComponent(viewComponent, newContext)); } catch (Exception e) { throw new TemplateRenderingException("Error rendering view component " + componentName, e, token.TokenPosition); } }
protected override CompiledTemplate OnEvalParseFile(ExpressionParser parser, TemplateParser templateParser, string fileName, TemplateToken token, IParserContext context, out Dictionary <string, IValueWithType> parameters) { TemplateParserContext parserContext = (TemplateParserContext)context; TemplateToken.ParameterizedExpression pExpr = token.ExtractParameters(); parameters = new Dictionary <string, IValueWithType>(StringComparer.InvariantCultureIgnoreCase); foreach (KeyValuePair <string, string> var in pExpr.Parameters) { parameters[var.Key] = parser.Evaluate(var.Value, context); } return(parserContext.Template.CompileSubTemplate(parser.Evaluate <string>(pExpr.MainExpression))); }
protected override CompiledTemplate OnEvalParseFile(ExpressionParser parser, TemplateParser templateParser, string fileName, TemplateToken token, IParserContext context, out Dictionary <string, IValueWithType> parameters) { TemplateParserContext parserContext = (TemplateParserContext)context; TemplateToken.ParameterizedExpression pExpr = token.ExtractParameters(); parameters = new Dictionary <string, IValueWithType>(StringComparer.InvariantCultureIgnoreCase); foreach (KeyValuePair <string, string> var in pExpr.Parameters) { parameters[var.Key] = parser.Evaluate(var.Value, context, token.TokenPosition); } ICompiledTemplate subTemplate = parserContext.Template.CompileSubTemplate(parser.Evaluate <string>(pExpr.MainExpression, context, token.TokenPosition)); //TODO : fix this. It should be possible to include templates with different syntax return(((ViciCompiledTemplate)subTemplate).CompiledTemplate); }