Overview
Hello, I am learning Ember.js and I am connecting to a Wordpress site I control via the Wordpress JSON API plugin.
Using the JSON API from the plugin I'm able to easily pull in the WordPress post title, author name, publish date, post excerpt, etc for any post without problems. However, when I try and use the post content, I get [object Object] back instead of the expected string.
Looking directly at the JSON object I'm working with, both excerpt and content are items in the JSON object which are each equal to a string of HTML. The only difference between the two appears to be the length of the string. using {{{excerpt}}} returns the string and allows the HTML to be properly formatted while {{{content}}} just prints out '[object Object]'.
The Handlebars Template
<script type="text/x-handlebars" id="post">
<div class="post">
<h1>{{title}}</h1>
<h2>by {{author.name}} <small class="muted">({{date}})</small></h2>
<hr>
<div class="below-the-fold">
{{{content}}}
</div>
</div>
The Rendered HTML by Ember
<div class="post">
<h1>Sample Post</h1>
<h2>by Boydbme <small class="muted">(2015-01-10 11:32:36)</small></h2>
<hr>
<div class="below-the-fold">
[object Object]
</div>
</div>
the JSON object I'm working with
post: {
id: 1306,
type: "post",
slug: "sample-post",
url: "#removed_for_stack_overflow",
status: "publish",
title: "Sample Post",
title_plain: "Sample Post",
content: "<p class="p1"><span class="s1">Lorem harum fuga.</span></p> <p class="p1"><span class="s1">Lorem dolor fuga.</span></p> <p class="p1"><span class="s1">Lorem ipsuuga.</span></p> <p class="p1"><span class="s1">Lorem dolor</span></p> <p class="p1"><span class="s1">Lorem harum fuga.</span></p>",
excerpt: "<p>Lorem ipsum dolor sit fuga.<a class="read-more" href="#removed_for_stack_overflow">Read More »</a></p> ",
date: "2015-01-10 11:32:36",
modified: "2015-01-10 11:32:36",
categories: [],
tags: [],
author: {},
comments: [],
attachments: [],
comment_count: 0,
comment_status: "closed",
thumbnail: "#removed_for_stack_overflow",
custom_fields: {},
thumbnail_size: "post-thumbnail",
thumbnail_images: {}
},
Any help would be greatly appreciated. My confusion comes from being able to use {{{excerpt}}} and get a string in my template as expected, but being unable to do the same with {{{content}}}.
Thanks!
Update:
@rené got it right in the comment below. {{{content.content}}} fixes the issue because I was colliding with an internal object.
{{{content}}}by{{log content}}, and watch the Console.contentis used for some internal stuff by Ember and Ember Data, particularly for Promise arrays and IIRC also in DS.Model. Most likely, you will need{{{content.content}}}instead, but it depends on what class instance gets passed to Handlebars in the end.{{{content.content}}}did the trick! Is there something else I could be doing that would prevent this behavior?{{{this.content}}}didn't fix the error, but{{{content.content}}}just doesn't seem right to me.content, in this case, is where the actual properties are. When you use a different property, likeexcerpt, it callsthis.get('excerpt'), which will in turn callthis.get('content').get('excerpt'), basically. I think the only options are to usecontent.content, or to rename the content properties in your Models, if you can.