Skip to content

Sub-component support? #15

@Bluecoaster455

Description

@Bluecoaster455

I was wondering if it is possible to be able to include components into components within the same TemplateProcessor?

Here's a sample command of what I'm doing:

 public static class HyUITestCommand extends AbstractPlayerCommand {
        public HyUITestCommand() {
            super("hyuitest", "Test a HyUI page");
        }

        @Override
        protected void execute(
                @NonNull CommandContext commandContext,
                @NonNull Store<EntityStore> store,
                @NonNull Ref<EntityStore> ref,
                @NonNull PlayerRef playerRef,
                @NonNull World world) {
            var html = new TemplateProcessor()
                    .registerComponent("mySubComponent",
                            """
                                <p>Hello subComponent!</p>
                            """)
                    .registerComponent("myComponent",
                            """
                            <div>
                                {{@mySubComponent}}
                            </div>
                            """)
                    .process("""
                            <div class="container">
                                {{@myComponent}}
                            </div>
                            """);

            PageBuilder.detachedPage()
                    .withLifetime(CustomPageLifetime.CanDismiss)
                    .fromHtml(html)
                    .open(playerRef, store);
        }
    }

This is what I am currently getting:
Image

I suppose right now components cannot be called in a registerComponent but perhaps to get around for me is to process templates in different steps and stitch all the resulting htmls together at the end which is a bit more work but doable.

Side note: It works when inside an {{#each ...}} block.

EDIT:

When I wrap the subcomponent call into a {{#if true}} it renders:

.registerComponent("myComponent",
                            """
                            <div>
                                {{#if true}}
                                    {{@mySubComponent}}
                                {{/if}}
                            </div>
                            """)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions