Nustache.Core.RenderContext.Include C# (CSharp) Method

Include() public method

public Include ( string templateName, string indent ) : void
templateName string
indent string
return void
        public void Include(string templateName, string indent)
        {
            if (_includeLevel >= IncludeLimit)
            {
                throw new NustacheException(
                    string.Format("You have reached the include limit of {0}. Are you trying to render infinitely recursive templates or data?", IncludeLimit));
            }

            _includeLevel++;

            var oldIndent = _indent;
            _indent = (_indent ?? "") + (indent ?? "");

            TemplateDefinition templateDefinition = GetTemplateDefinition(templateName);

            if (templateDefinition != null)
            {
                templateDefinition.Render(this);
            }
            else if (_templateLocator != null)
            {
                var template = _templateLocator(templateName);

                if (template != null)
                {
                    // push the included template on the stack so that internally defined templates can be resolved properly later.
                    // designed to pass test Describe_Template_Render.It_can_include_templates_over_three_levels_with_external_includes()
                    this.Enter(template);
                    template.Render(this);
                    this.Exit();
                }
            }

            _indent = oldIndent;

            _includeLevel--;
        }

Usage Example

示例#1
0
 public override void Render(RenderContext context)
 {
     context.Include(_name, _indent);
 }
All Usage Examples Of Nustache.Core.RenderContext::Include