Skip to content

Layout overriding block with inline #300

Closed

Description

@fhogberg

Tried using a layout inheritance and defining blocks inline.
Am i doing something wrong or is this currently not supported?

        public void PartialLayoutAndInlineBlock()
        {
            string layout = "{{#>body}}{{fallback}}{{/body}}";
            string page = @"{{#>layout}}{{#*inline ""body""}}{{truebody}}{{/inline}}{{/body}}{{/layout}}";


            var template = Handlebars.Compile(page);

            var data = new
            {
                fallback = "aaa",
                truebody = "Hello world"
            };

            using (var reader = new StringReader(layout))
            {
                var partialTemplate = Handlebars.Compile(reader);
                Handlebars.RegisterTemplate("layout", partialTemplate);
            }
            var result = template(data);
            Assert.Equal("Hello world", result);
        }

Activity

  1. olegolo commented on Oct 22, 2020

    @olegolo

    Any progress on this?

  2. oformaniuk commented on Nov 2, 2020

    @oformaniuk
    Member

    Hello @olegolo .
    Unfortunately resources of supporters are limited and we're not capable of handling all the issues simultaneously. The main priority for now is 2.0 release.
    If this is critical functionality for you I'd kindly ask to help with the investigation and fixing.

  3. olegolo commented on Nov 2, 2020

    @olegolo

    Problem statement:
    Having a layout
    Handlebars.RegisterTemplate("layout", @"Hello {{>sec1}}" and {{>sec2}}");
    and a template
    {{#*inline 'sec1'}} Tom {{/inline}} {{#*inline 'sec2'}} Jerry {{/inline}}

    Expected result: Hello Tom and Jerry
    Actual result: Hello and Jerry

    After some experiments, I found out that the first section is always used for the 'everything else' like the texts outside of sections.

    Workaround#1 inverse dependencies and register template as partial

    Workaround#2 having a layout with the first Default section
    {{#*inline 'garbage'}} this is going to fall into hidden div for example {{/inline}} {{#*inline 'sec1'}} Tom {{/inline}} {{#*inline 'sec2'}} Jerry {{/inline}}

    Suggestion
    Add the ability to completely disable garbage content and omit the first (mandatory to make it work) section.

  4. oformaniuk commented on Nov 2, 2020

    @oformaniuk
    Member

    Possibly related issue: /issues/300

  5. oformaniuk commented on Nov 2, 2020

    @oformaniuk
    Member

    Had a quick look at the issue.
    The problem is related to the order we execute *inline. *inline has decorator behaviour and should be executed as the first statement on the block. Unfortunately right now it's not handled in this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions