I am trying to create a view mode that gives a content editor the option of selecting the view mode, so that they can display different fields. I was trying to do this for a single node display and just noticed that the comments field (which displays all the comments for the node) is not available in my view mode. I have looked through all my view modes to see if they have that field and they do not. Only the standard "full content" view mode has the comments template.

Is there a way to include the the comments field in a custom view mode? I am sure one can do it via a custom code field, but it seems that one should have the option of adding it by default through the GUI. Perhaps I have something configured wrong in the GUI that is not making the comments thread available as a field in the view mode?

Would appreciate some help with this & thank you!

Comments

RKopacz’s picture

Ok so I tried printing the comment variable in the display suite custom code section:

<?php print render($content['comments']); ?>

Doesn't work. Any thoughts on this? Would appreciate some help.

RKopacz’s picture

Status: Active » Closed (works as designed)

Ok never mind. I figured it out. You can create a dynamic field which will be available to the view mode, which will display the node's comments. Any one who isn't sure how to do it can watch this video at Drupalize.me, which explains how to do it.

While it's good that Display Suite can do this, I do think the comment field which is available to the full content view should also be available to other view modes by default, without having to go through all that.

Hope this helps someone, a least.

rajmataj’s picture

Would you mind outlining what exactly you're putting into the dynamic field to get it to show the comments? I have seen the video and tried selecting node > comments for the content but still had no luck.

On a different but related note, I noticed something weird for the comments.

  • With the view mode 'full content' enabled, I had then turned on comments for a particular content type (maybe that was the problem? Enabling comments after a view mode was created?) Anyhow, the comments field was available on my 'full content' view mode, but it would never appear when viewing that node even though I know there are comments there. After clearing the cache, it still would not show on the page for that node when looking at some saved content.
  • If I disabled that view mode entirely, the fallback is now the 'default' view mode, and using that, Comments show up. Great, except I need the regions of Display Suite to ideally put comments wherever I want them.
  • Now here is where it gets strange, and perhaps someone can explain to me what is happening..? When I go to the default view mode and again enable my previously deactivated 'full content' view mode with the Comments in a visible region where I left them, I can then see the Comments showing on the full node! But... why? Is this a bug?

Any kind of definitive way to assign Comments to a region in a Display Suite view mode would be super helpful. At least this is now working for me but I'd like to understand why. Again, please @RKopacz if you could also provide the code or steps you took with the dynamic field to get comments to show, please reply here. Thanks! Display Suite is an awesome module.

oeroek’s picture

Great help. I ran into exactly the same problem and the video at drupalize.me pointed me in the rigt direction. Basically you need to do the following.

If you have a custom view mode it seems that comments and comment form are not shown as a Display Suite field. In full mode the are.

You make 2 dynamical fields. Name is of no importance. On your custom view mode you move both fields into the content so they are visible. In the settings of each field you can select the content that should be shown. The first field: node->node comments. The second field: node-> comment form. Save and youre done.

deakbalazs’s picture

Comment module is hardcoded for 'full' view mode, but you can turn on comments for other node voew modes via hook_node_view(). Here is an example:

function MyModule_node_view($node, $view_mode, $langcode) {
	if ($view_mode == 'MyCustumViewModeName') {
		comment_node_view($node, 'full');
	}
}

Also you can define special view mode for comments via kormanyablak_entity_info_alter() :

function MyModule_entity_info_alter(&$entity_info) {
	$entity_info['comment']['view modes']['MyCustumViewModeName'] = array(
		'label' => t('MyCustumViewModeDisplayName'),
		'custom settings' => TRUE,
	);
}

This will show a new view mode tab on the contettype's structure comments display settings admin-page.

webservant316’s picture

Issue summary: View changes

I am trying to use the code suggested in #5. comment_node_view() is called, but comments still do not display. any ideas?

proweb.ua’s picture

I am trying to use the code suggested in #5. comment_node_view() is called, but comments still do not display. any ideas?

same problem

webservant316’s picture

I figured it out instead by using DS Dynamic Fields and choosing the comment field for display.

nikolay borisov’s picture

Saw there is no working answer here.
I am really not a fan of DS but I had to do it for an inherited project and here is a solution that works:

You could create a Code field, select for Entities : Node, and for code the following:


if (!empty($entity->nid)) {
$comment = comment_node_page_additions($entity);
print render($comment); 
}

Then you just have to drag it in your display.

webservant316’s picture

#8 is also a working answer.

nikolay borisov’s picture

in my case it was not working (maybe because the display was used for a node from a View)

AndersEkman’s picture

Another way to solve this is by creating a view that displays the comments, and then attach it to the desired view mode using the Entity Views Attachment module.

Some tips:

  • Use a contectual filter on Comment:Nid to only get comments for the current node.
  • Add a sort on Comment:Thread if you want to preserve the hierarchy.