kylenstone / kylethinks

professional blog
0 stars 0 forks source link

replace navigation with json object data and handlebars partial #34

Open kylenstone opened 6 years ago

kylenstone commented 6 years ago
<ul class="nav-list">
{{#each nav}}
  <li>
    <div class="nav-item-title"><a href="{{ path }}">{{log data.nav.title }}</a></div>
    <div class="nav-item-description">{{ nav.description }}</div>
  </li>
{{/each}}
</ul>
<script>
// Create a JSON object with the page's content
var data = {
   nav: [
      {
         url: "/",
         title: "Home",
         class: "home"
      }, {
         url: "work/",
         title: "My work",
         class: "work"
      }
   ]};

// Pass the JSON object to your content.handlebars template
var pageContent = Handlebars.templates.content(data);

// Append the page content to the body element
$('body').append(pageContent);
</script>

Alternatives

issue: use metadata in handlebars helper functions moremeta (i.e. in this example)

kylenstone commented 6 years ago

Also read: https://stackoverflow.com/questions/36756532/access-single-object-in-model-using-metalsmith-and-swig

kylenstone commented 6 years ago

Also see how it was done on brophy.org