What is a proper way to {{render ...}} sub-component with handler defined in parent-component's config?
Currently in our team we successfully solved this in a wierd way:
{{render '@handler' subComponentContext merge=true}} where subComponentContext property is defined in a YAML config as a string "@handler--variant". Note that @handler and @handler--variant should match the component e.g. name handler.
In other case we tried in eq. {{render subComponentContext}} which generates an error.
I'm not sure if our "wierd way solution" is a bug or a feature... :thinking:
Seems like a duplicate of #195
Hey @tlenex, I've tried to use your workaround but I couldn't understand or get your advice to work.
Steps I took:
handler.hbsmy-module.hbs within which I want to use dynamic partialsmy-module.config.yml, e.g. dynamicPartial: '@another-partial'{{> render '@handler' dynamicPartial merge=true}}This does not work for me. Could you explain what you have in each of your partials possibly?
@iamkeir drop point 1, handler name was just an example for component name.
Try this:
my-module.hbs and another-partial.hbs. my-module.config.yml and another-partial.config.ymlanother-partial needs to have an variant (docs here) in it's config file. Set that variant's name to my-variant, so the handler for this variant should be @another-partial--my-variant. another-partial.config.yml should look like:
variants:
- name: 'my-variant'
my-module's context property in my-module.config.yml, e.g. dynamicPartial: '@another-partial--my-variant'my-module.config.yml should look like:
context:
dynamicPartial: '@another-partial--my-variant'
my-module.hbs write {{render '@another-partial' dynamicPartial merge=true}}. Note that in step 5 I used non-variant handler @another-partial, the variant handler lies in dynamicPartial string context property set in step 4. Both strings should match the same component and one of it's variants.
Note this "hack" only works for variants.
Note you can create another-partial--my-variant.hbs with completely new HTML template.
Thanks @tlenex, it worked! Really appreciated - but wow, how odd!
@iamkeir you're welcome, but keep in mind, that this might be a bug or rather unintended feature.
@allmarkedup @dkhuntrods could you tell, if example above is a bug or a feature? :)
Yeah, noted. I'm impressed you found it!
@tlenex What's happening there is that you're telling Fractal to render@another-partial with @another-partial--my-variant's context data. By default, any defined views (in this case, the *.hbs file) are included with a variant's context data, which is why this works.
There's no plan to change this behaviour in v1, but things will work quite differently in v2.
For more on using lookups, see here https://github.com/frctl/fractal/issues/278#issuecomment-316977660
Most helpful comment
For more on using lookups, see here https://github.com/frctl/fractal/issues/278#issuecomment-316977660