The result of portal.getContent()


    key: "key-to-content"

supposed to give the same result no matter where in the code it is called?

Hi Helge,

Yes, depending on which Content Type is behind the Content that triggers this Part controller to fire up.

On viewing a Page Template the current Content is the Page Template, and that would show some data that is different than if you’re previewing a Landing Page.

So the passed-in key argument doesn’t affect which content is returned?

Sorry, read the question wrong. Just assumed you did:


That should give the same result yes. Perhaps some context data will change, but not the “” part of the JSON.

Are you getting something weird?

I sorted it out by using

content.get({key: "my-key"}) 

instead of

portal.getContent({key: "my-key"})

However, I had in controller.js:

var key = "my-key";
var data = portal.getContent({key: "my-key"})
// Here, data._id === key 

Then I wanted to attach some functions to data, thus I placed a function in /lib/ContentModel.js:

var ContentModel = function(key) {
   if(key) { = portal.getContent({key: key})    
   } else { = portal.getContent(); 

Then in controller.js:

var ContentModel = require("/lib/ContentModel.js")
var key = "my-key"; 
var model = new ContentModel(key);

In this case, I would expect === key, but seems to be the key of the page instead the content that I wanted… I did quite a bit of debugging, but chances are I have overlooked something :slight_smile:

As I mentioned, content.get({key: key}) worked for me:

// /lib/ContentModel.js: 
var ContentModel = function(key) {
   if(key) { = content.get({key: key})    
   } else { = portal.getContent(); 

Portal.getContent is a different function than lib-content’s getContent.

The first has no params if I remember correctly…