wpf style template selection process in polymer template ref & databinding

75 views
Skip to first unread message

aappd...@gmail.com

unread,
May 15, 2014, 10:00:21 AM5/15/14
to polym...@googlegroups.com
Is there any way to set a template selection "ref" that can be chained to the default algorithm which selects by ref name?

I typically bind to json data and wanted to have a template automatically selected based on a "type" field in my json object.

I do not mind loading 10-15, relatively small templates up front for the different types of visual presentations for specific data objects in my webapp.

Eric Bidelman

unread,
May 15, 2014, 2:20:36 PM5/15/14
to aappd...@gmail.com, polymer-dev
Can you just use conditional templates for this?

<template if="{{jsonObj.type == 'foo'}}">
  ...
</template>

<template if="{{jsonObj.type == 'bar'}}">
  ...
</template>


Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/906b1429-ca0e-48cc-8d6e-602c1b7d1e8b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

aappd...@gmail.com

unread,
May 15, 2014, 4:38:02 PM5/15/14
to polym...@googlegroups.com, aappd...@gmail.com
I'll give that a try and see if works and how it feels. I was hoping that that I could place a "function" into the ref, or add an "element" to the page that sets a strategy handler somewhere and have that handler run to perform the selection e.g. search the dom. That way the logic is not scattered around on the templates themselves.

Scott Miles

unread,
May 15, 2014, 6:28:12 PM5/15/14
to aappd...@gmail.com, polymer-dev
Every Polymer element has this (prototypical) method:

    fetchTemplate: function(elementElement) {
      return elementElement.querySelector('template');
    }

You can override this method to return whatever template you want, just keep in mind that it may get called more than once if your element has other Polymer superclasses.



aappd...@gmail.com

unread,
May 15, 2014, 8:39:06 PM5/15/14
to polym...@googlegroups.com, aappd...@gmail.com
I'll look into that as well. I've also been using the TemplateBinding library e.g. templates without polymer elements so straight up it would not work.

However, maybe all I need to do is define something like a UserElement that is merely designed to wrap around some content and optionally reference a template to use in its interior. Then I could override the prototype function without disrupting the rest of the world. 
Reply all
Reply to author
Forward
0 new messages