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

Nested templates #1

Closed
g105b opened this issue Oct 30, 2017 · 0 comments
Closed

Nested templates #1

g105b opened this issue Oct 30, 2017 · 0 comments
Labels

Comments

@g105b
Copy link
Member

g105b commented Oct 30, 2017

A nice improvement made in v2 is to be able to insert a templated element back where it originally came from, without having to select its parent in any way. It does this by storing a reference to its parent as it gets extracted from the DOM into the Template object.

Then when you come to add it back to the page, you can do this:

$messageItem = $this->document->getTemplate("message-item");
$messageItem->insertTemplate();

The insert part was crucial - rather than append, it remembers the sibling element too in order to keep its original place.

But the question is, where does (or should) the template named "message-item" get inserted in the following example:

<div data-template="conversation">
    <h1>Title</h1>
    <ul class="messageList">
        <li data-template="message-item">
            Message content
        </li>
    </ul>
</div>

Once the first conversation element has been inserted, should inserting message-item elements go into the original, or the latest added? If the latter, how do we define this?

It might make most sense to do something like the following:

  • Templated elements need to remember their ancestors with data-template attributes.
  • When being inserted, templated elements need to search for the latest-added data-template ancestor.
  • Some clever XPath here?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant