Skip to content
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

dynamic custom tag names #94

Closed
yomed opened this issue Jun 25, 2015 · 5 comments
Closed

dynamic custom tag names #94

yomed opened this issue Jun 25, 2015 · 5 comments

Comments

@yomed
Copy link
Contributor

yomed commented Jun 25, 2015

I would like to determine which custom tags get called via my renderer.js

So in the renderer, something like this:
data.details=['d1','d2','d3']

And then in template.marko (which doesn't work):
<for each="detail in data.details">
    <${detail} />
</for>

One solution would be to explicitly call out tags conditionally:
<for each="detail in data.details">
    <if test="detail==='d1'">
        <d1 />
    </if>
</for>

But is there any other way to accomplish this?

@patrick-steele-idem
Copy link
Contributor

Hi @yomed, instead of a custom tag (which is associated with a renderer function) you can invoke a renderer(input, out) function directly:

data.renderers=[
    require('../foo'),
    require('../bar'),
    require('../baz')
]
<for each="renderer in data.renderers">
    <invoke function="renderer(myInputObject, out)"/>
</for>

I don't know exactly how that fits into your app, but hopefully you get the idea. FYI, a custom tag is resolved to a renderer at compile-time.

Please let me know if that doesn't solve your problem.

@yomed
Copy link
Contributor Author

yomed commented Jun 29, 2015

Thanks Patrick, that seems to work well. Do you know how I might include w-id in this case?

So that

<detail w-id="detail[]" />

would become something like this...

<invoke function="renderer(data, out)" w-id="detail[]" />

@patrick-steele-idem
Copy link
Contributor

Assigning a w-id attribute to an <invoke> tag currently doesn't work because of how the compile-time transform is implemented for marko-widgets. I'll look into seeing if it can be supported with a small code change. Can you please open a Github issue against the marko-widgets project?

@yomed
Copy link
Contributor Author

yomed commented Jun 29, 2015

Ok thanks. That would be great if this could be supported.

@patrick-steele-idem
Copy link
Contributor

marko-widgets was updated to support the w-id attribute with the <invoke> tag: marko-js-archive/marko-widgets#46

Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants