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

Feature Request: Bind/Map to Tags #45

Open
leeola opened this issue Mar 7, 2012 · 3 comments
Open

Feature Request: Bind/Map to Tags #45

leeola opened this issue Mar 7, 2012 · 3 comments

Comments

@leeola
Copy link

leeola commented Mar 7, 2012

I'd like to request the ability to bind and/or map onto tags themselves.

A simple example would be to bind additional <link> or <script> tags into the body of the <head> element.

Note that i am aware, in this example, that you could give <head> an id, or a class, but that just seems silly. I think it would be a perfectly reasonable use case to be able to insert data into the bodies of elements, especially for single element types such as head or body.

Some additional thoughts..

  • Prefix, Suffix, or Replace insertion would be nice. So you could insert the data into the beginning or end of the element, or replace it's content all together.
  • Multiple Matches. When dealing with tags such as <head> or <body> you'll often run into only one, but if you try and bind data to <li>, you'll likely match many more. With that said, you should be able to resolve which match(s) you would like to bind the data to.. or all of them?
@Prestaul
Copy link

Prestaul commented May 5, 2012

Yes, please. I'd like to be able to populate the <title> tag without needing to add an id (or other attribute) to it.

Another possible option is to provide a mechanism for removing the binding attribute. E.g. map.where('data-bind').is('title').use('title').removeAttribute(); It would be ugly in our templates but at least it wouldn't make it to the output...

@framp
Copy link

framp commented Aug 5, 2012

+1

Imho, this would be useful mainly for unique elements like title
I don't see any problems in adding a class to some repeating elements, but adding an id to <title> is quite ugly

@sydcanem
Copy link

working for me..
var html = "<title></title>";
var data = {"title":"The Title"};
map.tag("title").use("title");

plates.bind(html, data, map);

<title>The Title</title>

But it has a weird behavior of appending the text inside the title tag if it already had inside..

var html = "<title>The Title</title>";
var data = {"title":"Another Title"};
map.tag("title").use("title");

plates.bind(html, data, map);

<title>Another TitleThe Title</title>

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

4 participants