Using custom elements in the content element with polymer

user715564

I'm trying to get a grasp on polymer and the shadow dom. Is it possible to use custom elements inside of custom elements when dealing with dynamic content? For example, in WordPress I can use <?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?> to list out my menu links. If I create a <main-menu> element for my menu, how would I wrap another custom element around each <li>?

Here is my main-menu html file:

<link rel="import" href="/components/polymer/polymer.html">
<link rel="import" href="/components/core-header-panel/core-header-panel.html">
<link rel="import" href="/components/core-toolbar/core-toolbar.html">
<link rel="import" href="/components/paper-tabs/paper-tabs.html">

<polymer-element name="main-menu">
<template>
<style>

.main-menu ::content ul li {
  float: left;
  list-style-type: none;
  margin-left: 20px;
}

core-header-panel {
  height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch; 
}
core-toolbar {
  background: #03a9f4;
}

core-toolbar ::content ul li a {
  color: white;
  text-decoration: none;
  font-size: 14px;
  text-transform: uppercase;
}

</style>

<core-header-panel>
  <core-toolbar>
    <div class="main-menu">
      <paper-tabs>
        <content select="li"><paper-tab></paper-tab></content>
      </paper-tabs>
    </div>
  </core-toolbar>
</core-header-panel>

</template>
<script>
Polymer({});
</script>
</polymer-element>

Obviously, using <content select="li"><paper-tab></paper-tab></content> doesn't accomplish what I want to do but I am not sure how I would go about wrapping <paper-tab> around each <li>

robdodson

In this instance, you'll need to use the getDistributedNodes method to grab all of those lis, turn them into an Array, and hand that off to a repeating template. This thread has a bit more explanation: Element transclusion

Here's an example (http://jsbin.com/hazay/9/edit):

<polymer-element name="main-menu">
  <template>
    <style>
      :host {
        display: block;
      }
      ::content > * {
        display: none;
      }
    </style>
    <content id="c" select="li"></content>
    <paper-tabs>
      <template repeat="{{item in items}}">
        <paper-tab>{{item.textContent}}</paper-tab>
      </template>
    </paper-tabs>
  </template>
  <script>
    Polymer({
      items: [],
      domReady: function() {
        // .array() is a method added by Polymer to quickly convert
        // a NodeList to an Array
        this.items = this.$.c.getDistributedNodes().array();
      }
    });
  </script>
</polymer-element>

<main-menu>
  <li><a href="#">Foo</a></li>
  <li><a href="#">Bar</a></li>
  <li><a href="#">Baz</a></li>
</main-menu>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Dart - Polymer Custom Element not loaded

From Dev

Query elements inside <content> of a custom element

From Dev

Using Polymer core elements in Dart

From Dev

Polymer: How to access elements within the 'content' tag

From Dev

Polymer custom element with template-as-content

From Dev

Bind data to content element in Polymer

From Dev

polymer duplicate element content

From Dev

Polymer querySelector can't find custom polymer element in polymer element

From Dev

Issues using Owl Carousel as a custom element with Polymer

From Dev

Using jquery toggle() inside a custom polymer element

From Dev

Polymer Dart Custom Element not executing

From Dev

How to access inner elements of an custom element defined through Polymer

From Dev

Polymer custom element will not style

From Dev

How to querySelector elements of an element's DOM using Polymer

From Dev

Google Polymer - how to add content to Neon elements

From Dev

Adding elements to a SVG in Polymer element

From Dev

Query elements inside <content> of a custom element

From Dev

Using custom elements in the content element with polymer

From Dev

Using JavaScript in Polymer element

From Dev

Polymer input label using content

From Dev

Pseudo elements on Polymer custom element does not work

From Dev

Polymer custom element with template-as-content

From Dev

Polymer: Using querySelector in Custom Element instead of "this.$."

From Dev

Polymer querySelector can't find custom polymer element in polymer element

From Dev

Issues using Owl Carousel as a custom element with Polymer

From Dev

Polymer: Create a "general" custom element

From Dev

Polymer custom element will not style

From Dev

Creating a custom Polymer element

From Dev

Google Polymer - how to add content to Neon elements

Related Related

  1. 1

    Dart - Polymer Custom Element not loaded

  2. 2

    Query elements inside <content> of a custom element

  3. 3

    Using Polymer core elements in Dart

  4. 4

    Polymer: How to access elements within the 'content' tag

  5. 5

    Polymer custom element with template-as-content

  6. 6

    Bind data to content element in Polymer

  7. 7

    polymer duplicate element content

  8. 8

    Polymer querySelector can't find custom polymer element in polymer element

  9. 9

    Issues using Owl Carousel as a custom element with Polymer

  10. 10

    Using jquery toggle() inside a custom polymer element

  11. 11

    Polymer Dart Custom Element not executing

  12. 12

    How to access inner elements of an custom element defined through Polymer

  13. 13

    Polymer custom element will not style

  14. 14

    How to querySelector elements of an element's DOM using Polymer

  15. 15

    Google Polymer - how to add content to Neon elements

  16. 16

    Adding elements to a SVG in Polymer element

  17. 17

    Query elements inside <content> of a custom element

  18. 18

    Using custom elements in the content element with polymer

  19. 19

    Using JavaScript in Polymer element

  20. 20

    Polymer input label using content

  21. 21

    Pseudo elements on Polymer custom element does not work

  22. 22

    Polymer custom element with template-as-content

  23. 23

    Polymer: Using querySelector in Custom Element instead of "this.$."

  24. 24

    Polymer querySelector can't find custom polymer element in polymer element

  25. 25

    Issues using Owl Carousel as a custom element with Polymer

  26. 26

    Polymer: Create a "general" custom element

  27. 27

    Polymer custom element will not style

  28. 28

    Creating a custom Polymer element

  29. 29

    Google Polymer - how to add content to Neon elements

HotTag

Archive