Example #1
0
        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, token.TokenPosition));
            }

            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);
            }
        }
Example #2
0
        public static string RenderComponent(View view, string name, params object[] parameters)
        {
            TemplateParserContext newContext = new TemplateParserContext(view, view.ViewTemplate);

            for (int i = 0; i < parameters.Length ; i+=2)
                newContext.SetLocal((string) parameters[i], parameters[i+1], parameters[i+1] == null ? typeof(object) : parameters[i+1].GetType());

            return WebAppHelper.RunViewComponent(WebAppHelper.GetViewComponent(name), newContext);
        }
Example #3
0
        public static string RenderComponent(View view, string name, params object[] parameters)
        {
            TemplateParserContext newContext = new TemplateParserContext(view, view.ViewTemplate);

            for (int i = 0; i < parameters.Length; i += 2)
            {
                newContext.SetLocal((string)parameters[i], parameters[i + 1], parameters[i + 1] == null ? typeof(object) : parameters[i + 1].GetType());
            }

            return(WebAppHelper.RunViewComponent(WebAppHelper.GetViewComponent(name), newContext));
        }