It is not showing content attributes

Hi @ynaka,

Can you please check your objectID: 8568560 it does not appear to have a Comment

This is causing this line of your code:

const highlighted = item._highlightResult;
...
 for (let i = 0; i < highlighted.Comment.length; i++) {
...

To return an error in the console of the sandbox because of the undefined Comment:

TypeError
Cannot read property 'length' of undefined

Once resolved, does that help you access the necessary attributes for display?

Hi, I edited your code but when it comes to the different hierarchy, it’s not displaying even if it returns true.
Searched word “ぜひ!”

Eventually I want to do line this.

	for (let i = 0; i < snippet.Comment.length; i++) {
		if(snippet.Comment[i].COMMENT_Detail && snippet.Comment[i].COMMENT_Detail.matchLevel === 'full'){
			var numComm = i;
		}
	}

    item.isComment_Detail = highlighted.Comment &&
	   highlighted.Comment[0].COMMENT_Detail.matchLevel === 'full';

Hi there,

Let me try to help here.
If I understand correctly the issue is that you are not seeing COMMENT_Detail display in the result.
The object COMMENT_Detail is not at the root of your object and is embedded in Comment that is an array.

Instead you can try doing :
{{#isComment_Detail}}{{#helpers.highlight}}{ "attribute": "Comment.0.COMMENT_Detail" }{{/helpers.highlight}}{{/isComment_Detail}}

By testing that I noticed that it can happen for _highlightResult to be undefined. You’ll need to update item.isComment_Detail to check that _highlightResult exists.

I hope it helps!

1 Like

Hi,
Thanks for your help!

Could you explain why I didn’t need [ ] for “attribute”: “Comment.0.COMMENT_Detail” ??

Also I am trying to do like this.

for (let i = 0; i < highlighted.Comment.length; i++) {
if(highlighted.Comment[i].COMMENT_Detail && highlighted.Comment[i].COMMENT_Detail.matchLevel === ‘full’){
var numComm = i;
}
}

This returns numComm = 0 as I expected.
then, this to display.

“attribute”: “Comment.numComm.COMMENT_Detail”

it seems not reading. Could you help me what’s wrong with this ?!
Thank you very much.

Hi,

You cannot use the numComm variable in the templating system, but alternatively you can store the wanted comment on the item._highlightResult object and then access it.

Here’s an example CodeSandbox with this solution:

Hi, I posted a question related to this please check it out.
Thanks.