Problem with content_by_ids and pages created with api

Highlighted
New Contributor

Hi, We did create some pages with 'page publishing api', http://forte-matt-p-dev-5940484-5940484.hs-sites.com/norway-master-projects is an example - but we spotted that we cannot fetch data from linked pages As You can see, `norway:REPLICATIONTEST | MASTER | PROJECT1` and `norway:REPLICATIONTEST | MASTER | PROJECT2` are published `https://imgur.com/I2vuDlG` In template `https://app.hubspot.com/design-manager/5940484/code/9976072867` we have code like
``` {% set ids = ((content.widgets.items()|map('value')|selectattr('id', 'equalto','children'))[0].body.children|map('pageLinkId')) %} ``` it selects first known module from page and is getting connected pages (this does work) later on we are calling `page_by_id()` method that seems to work ``` {{page_by_id(ids[0]).absolute_url}} {{page_by_id(ids[1]).absolute_url}} ```
But when we want to do the same with collection of pages it gives us empty result
``` {{content_by_ids(ids)|map('absolute_url')}} ```

Is there any workarround for that?

Reply
0 Upvotes
4 Replies 4
HubSpot Moderator

Hi @popielarzmatt , are you still seeing this issue? When I go to the page you linked, I can see 2 results in your results array: http://forte-matt-p-dev-5940484-5940484.hs-sites.com/norway-master-projects. I could be misunderstanding you here, but wanted to see if you'd solved it already.

Reply
0 Upvotes
New Contributor

Yeah, this problem still occurs when we do use `content_by_ids`, now we're using `page_by_id`, so it seems to work, but it's only workarround

Reply
0 Upvotes
HubSpot Moderator

Ah, I see. I must have overlooked your use of content_by_ids. Let me dig into that

Reply
0 Upvotes
HubSpot Moderator

Hi @popielarzmatt , after a lot of testing, I believe that this issue has to do with with inconsistent nature when using .append(). It's not currently a documented function, so I've been able to reproduce some odd behavior with it. That said, I don't see anything wrong with your code outside of the use of that function. I've confirmed when printing out with page_by_id and content_by_ids, that the data structure looks the same for both. 

 

I can also print out the array with the function  {{ functions.getPageByIds(results, ids) }} on the main page (without the do, does syntax -- if you could link that here that would be helpful). 

 

http://prntscr.com/nx1mui

http://prntscr.com/nx1mms

 

One thing I might suggest is doing all of your work - notably adding to the array - in your funtion macro. It might be a good idea to keep your results array inside of your macro, and then just print it out when you have all results back, rather than calling the function with do and setting the results array in the main file. It also may be tripping up there do to the async nature of a loop. 

 

Other than that, I think your function check at the moment is probably your best bet, as it appears to work for both content types. I'll bring this feedback to the product team as well to get some eyes on the issue.

Reply
0 Upvotes