Пример #1
0
        protected void ProcessTemplate(string name, Tag tag)
        {
            Template useTemplate = currentTemplate.FindTemplate(name);

            if (useTemplate == null)
            {
                string msg = string.Format("Template '{0}' not found", name);
                WriteError(msg, tag.Line, tag.Col);
                return;
            }

            // process inner elements and save content
            TextWriter saveWriter = writer;

            writer = new StringWriter();
            string content = string.Empty;

            try
            {
                ProcessElements(tag.InnerElements);

                content = writer.ToString();
            }
            catch
            {
                return;                 // on error, do not do tag inclusion
            }
            finally
            {
                writer = saveWriter;
            }

            Template saveTemplate = currentTemplate;

            variables = new VariableScope(variables);
            variables["innerText"] = content;

            try
            {
                foreach (TagAttribute attrib in tag.Attributes)
                {
                    object val = EvalExpression(attrib.Expression);
                    variables[attrib.Name] = val;
                }

                currentTemplate = useTemplate;
                ProcessElements(currentTemplate.Elements);
            }
            finally
            {
                variables       = variables.Parent;
                currentTemplate = saveTemplate;
            }
        }
Пример #2
0
 /// <summary>
 /// finds template matching name. If this template does not
 /// contain template called name, and parent != null then
 /// FindTemplate is called on the parent
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public virtual Template FindTemplate(string name)
 {
     if (templates.ContainsKey(name))
     {
         return(templates[name]);
     }
     else if (parent != null)
     {
         return(parent.FindTemplate(name));
     }
     else
     {
         return(null);
     }
 }