-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dynamicComponent missing context / handlebars dynamic partials broken #133
Comments
Dynamic partials also don't work:
results in: |
I don't think dynamicComponent is set up to pull in context. See my response on this thread here: https://support.bigcommerce.com/s/question/0D54O00006n4TTLSA2/possible-to-pass-a-parameter-to-the-product-options-dynamic-component |
@mattcoy-arcticleaf Yes, that is exactly the problem. The dynamic component is so you don't have to specify the type of the option, so you can avoid an ugly switch statement to include all possible option types. But without the context or even custom variables it is only good for a very narrow set of use cases and defeats the purpose of this helper. You get far more compatibility with a switch statement like this:
This could be one line if the dynamic component feature was fully implemented, but it is not. I consider this a bug. |
This is also a huge issue for me, again same use case. I need to access theme settings within the dynamic component, but I am unable to. Ideally I feel like you should be able to use the standard |
Actually, I'm not sure I understand why |
Specifically this: https://github.com/bigcommerce/stencil-cli/blob/master/lib/template-assembler.js#L98 is the problem. Since it can't detect usages of native dynamic partials, it's not loading any at all. |
@peterrakmanyi Here's a workaround for anyone wanting to use native dynamic components. Since the only thing preventing the native one working is the server not knowing how to load the templates, you just need to trick it into loading it the only way it knows how: the dynamic component helper {{#if false}}{{ dynamicComponent 'components/products/options'}}{{/if}}
{{#each product.options}}
{{> (concat 'components/products/options/' this.partial) theme_settings=../theme_settings}}
{{/each}} By making sure we wrap it in a conditional that never renders, we essentially just tricked it into loading all templates within |
@LordZardeck I'm getting the not found errors as well. When using the native dynamic partial syntax {{> (concat 'components/custom/webpage-content/page-' page.id)}} it'll say it's not found, even though I confirmed it matched completely. I also tried with your method with the if block and dynamic component. Even if I hardcode {{> (concat 'components/custom/webpage-content/default' '')}} works fine, which I find super strange. Change the name to anything else? Nope, even if the correct template is in the folder haha.. Below works for me so far, but it's not perfect as you have to manually reconstruct the this/context object with keys you want to pass, but at least has the flexibility of passing in extra keys like In this example in the {{#any
(if page.id '===' 91)
(if page.id '===' 94)
}}
{{#withHash
partial=(add 'page-' page.id)
page=page
pages=pages
urls=urls
}}
{{{dynamicComponent 'components/custom/webpage-content'}}}
{{/withHash}}
{{else}}
{{> components/custom/webpage-content/default}}
{{/any}}
{{> layout/base}} |
Didn't know {{#withHash
partial=(add 'page-' page.id)
}}
{{#with (extend this ../this)}}
{{{dynamicComponent 'components/custom/webpage-content'}}}
{{/with}}
{{/withHash}} |
I've just added a new theme setting to switch the way swatch options are rendered. It works fine, but the theme_settings object is not available in the context of the component.
This would normally be fixed by adding it as an input for the handlebars component and it works as expected.
{{> components/products/options/swatch theme_settings=../theme_settings}}
But, that is not how components are used for product options. The dynamicComponent custom helper decides which component to use, but does not add the inputs. This doesn't work:
{{{dynamicComponent 'components/products/options' theme_settings=../theme_settings}}}
What do you think about this?
The text was updated successfully, but these errors were encountered: