Sub-component support?
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:
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>
""")
Good point.
I'd like to also have components registered from files.
This will be fixed in 0.5.9.
Added in 0.5.9