コード例 #1
0
        public void RenderTemplate(string templateName, object model)
        {
            string templateFullPath = applicationInfo.AbsolutizePath("Web/Pages/Templates/" + templateName + ".vm.html");

            ITemplateSource template = new CacheableFileTemplate(
                templateFullPath,
                fileCache);
            string templateText = template.GetTemplate();

            VelocityEngine velocity = new VelocityEngine();
            velocity.Init();

            VelocityContext velocityContext = new VelocityContext();
            velocityContext.Put("m", model);
            velocityContext.Put("h", this);

            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                if (false == velocity.Evaluate(velocityContext, stringWriter, null, templateText))
                    throw new InvalidOperationException("Template expansion failed");

                writer.InnerWriter.Write(stringWriter.ToString());
            }

            writer.WriteLine();
        }
コード例 #2
0
        public void RenderTemplate(string templateName, object model)
        {
            string templateFullPath = applicationInfo.AbsolutizePath("Web/Pages/Templates/" + templateName + ".vm.html");

            ITemplateSource template = new CacheableFileTemplate(
                templateFullPath,
                fileCache);
            string templateText = template.GetTemplate();

            VelocityEngine velocity = new VelocityEngine();

            velocity.Init();

            VelocityContext velocityContext = new VelocityContext();

            velocityContext.Put("m", model);
            velocityContext.Put("h", this);

            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                if (false == velocity.Evaluate(velocityContext, stringWriter, null, templateText))
                {
                    throw new InvalidOperationException("Template expansion failed");
                }

                writer.InnerWriter.Write(stringWriter.ToString());
            }

            writer.WriteLine();
        }