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

Using custom elements in the content element with polymer

From Dev

Polymer custom element with template-as-content

From Dev

Polymer custom element with template-as-content

From Dev

Pseudo elements on Polymer custom element does not work

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: Using querySelector in Custom Element instead of "this.$."

From Dev

Issues using Owl Carousel as a custom element with Polymer

From Dev

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

From Dev

Query elements inside <content> of a custom element

From Dev

Query elements inside <content> of a custom element

From Dev

polymer duplicate element content

From Dev

Polymer custom element will not style

From Dev

Polymer custom element will not style

From Dev

Creating a custom Polymer element

From Dev

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

From Dev

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

From Dev

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

From Dev

Bind data to content element in Polymer

From Dev

Adding elements to a SVG in Polymer element

From Dev

Using JavaScript in Polymer element

From Dev

Dart - Polymer Custom Element not loaded

From Dev

Polymer Dart Custom Element not executing

From Dev

Polymer: Create a "general" custom element

From Dev

Polymer input label using content

From Dev

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

From Dev

Google Polymer - how to add content to Neon elements

From Dev

Google Polymer - how to add content to Neon elements

From Dev

Using Polymer core elements in Dart

Related Related

  1. 1

    Using custom elements in the content element with polymer

  2. 2

    Polymer custom element with template-as-content

  3. 3

    Polymer custom element with template-as-content

  4. 4

    Pseudo elements on Polymer custom element does not work

  5. 5

    Issues using Owl Carousel as a custom element with Polymer

  6. 6

    Using jquery toggle() inside a custom polymer element

  7. 7

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

  8. 8

    Issues using Owl Carousel as a custom element with Polymer

  9. 9

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

  10. 10

    Query elements inside <content> of a custom element

  11. 11

    Query elements inside <content> of a custom element

  12. 12

    polymer duplicate element content

  13. 13

    Polymer custom element will not style

  14. 14

    Polymer custom element will not style

  15. 15

    Creating a custom Polymer element

  16. 16

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

  17. 17

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

  18. 18

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

  19. 19

    Bind data to content element in Polymer

  20. 20

    Adding elements to a SVG in Polymer element

  21. 21

    Using JavaScript in Polymer element

  22. 22

    Dart - Polymer Custom Element not loaded

  23. 23

    Polymer Dart Custom Element not executing

  24. 24

    Polymer: Create a "general" custom element

  25. 25

    Polymer input label using content

  26. 26

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

  27. 27

    Google Polymer - how to add content to Neon elements

  28. 28

    Google Polymer - how to add content to Neon elements

  29. 29

    Using Polymer core elements in Dart

HotTag

Archive