I'm creating a custom theme and module for one of my content types. I want to show the comments link in a specific content type only if comments are turned on for the node or even globally for the content type specifically. I had originally used the following, simplified for example, in my tpl.php, which shows the link if the user has the privilege to comment. However, in my case, while I allow comments all over the site, I don't allow them on this particular content type. I want to leave the option open in case we do allow comments in the future.

 if (user_access('post comments')) {
  print '<a href="#">Comment</a>';

I was hoping that the system would recognize that a user that has privilege to comment every else still doesn't have privileges to comment on this node, and the link would not show, but it seems to show to anyone that has comment privileges, regardless of node.

What should replace user_access()?

  • are you using node.tpl.php?
    – No Sssweat
    Commented Aug 15, 2017 at 2:30
  • I'm using a node--mycontent.tpl.php specific to the content type. I have a sub module created for it, which includes that, a .module, special .css, etc.
    – Christia
    Commented Aug 15, 2017 at 2:34

1 Answer 1


If you look at https://api.drupal.org/api/drupal/modules%21node%21node.tpl.php/7.x

and click View source

enter image description here

and scroll down a bit, you will see that there is a variable that you can use:

$comment: State of comment settings for the node.

So my guess would be that the value is either 1 (TRUE) or 0 (FALSE).

Using Devel module you can use Devel's dpm() function, so put:


to dump and see it's value.

If my guess is correct, then you would need to do something like this:

 if ($comment == 1) {
    print '<a href="#">Comment</a>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.