HyUI icon indicating copy to clipboard operation
HyUI copied to clipboard

Sub-component support?

Open Bluecoaster455 opened this issue 10 months ago • 2 comments

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>
                            """)

Bluecoaster455 avatar Jan 28 '26 00:01 Bluecoaster455

Good point.

I'd like to also have components registered from files.

This will be fixed in 0.5.9.

Elliesaur avatar Jan 29 '26 00:01 Elliesaur

Added in 0.5.9

Elliesaur avatar Jan 30 '26 01:01 Elliesaur