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

[templates] How to handle expressions in tables #703

Open
justinfagnani opened this issue Nov 10, 2017 · 9 comments
Open

[templates] How to handle expressions in tables #703

justinfagnani opened this issue Nov 10, 2017 · 9 comments

Comments

@justinfagnani
Copy link
Contributor

Currently, this won't parse in a way that's useful for dynamically creating tables:

<template>
  <table>
    {{rows}}
  </table>
</template>

because the {{rows}} text will be fostered to before the table.

A couple of options are:

  • Offer a fallback syntax that can be parsed inside a table, like <!--{{rows}}--> or <?{{rows}}>
  • Change the parsing rules inside <template> so that disallowed content is not fostered.
@jakearchibald
Copy link

Parser changes can be limited to cases where the first non-whitespace chars are {{

@justinfagnani
Copy link
Contributor Author

If there are parser changes, I think we might still need a syntax fallback for older browsers using a template parts polyfill.

@matthewp
Copy link

@justinfagnani Am I reading this right, is the idea that you can pass something like a DocumentFragment as rows to createInstance()? Meaning values are not all toStringed? If so, what types are allowed?

@justinfagnani
Copy link
Contributor Author

@matthewp yes, the key type allowed besides Strings are Nodes, especially TemplateInstance form this proposal.

@jakearchibald
Copy link

TPAC: consensus for parser changes.

@wanderview
Copy link

I don't think anyone from mozilla parser team has weighed in yet. cc / @hsivonen

@jakearchibald
Copy link

Apologies, I just wanted to capture what happened in the room, it wasn't definitive (but I see how it can be read like that).

@dy
Copy link

dy commented Oct 24, 2020

That problem can be addressed purely symptomatically with a couple of strong heuristics.

  1. If there's insertion {{ }} right before the empty table, almost likely it was intended to be inside but parser hoisted it up.
  2. If the insertion {{ }} contains <tbody>, <tr>, <th> etc. - most surely it was supposed to reside in the <table>.

These two conditions I believe exclude practical chance user meant to place <tr> (or <thead> etc.) right before the empty <table>.

@dy
Copy link

dy commented Jan 15, 2022

As discovered in templize and uce-template, the simplest workaround is

<template>
  <table>
    <!--{{rows}}-->
  </table>
</template>

It has zero cost from performance/code size perspective.

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

No branches or pull requests

6 participants