0

I have created a block and the format of it's content is PHP CODE.

this block is available only full page of node type article.

now in my block , I want to access $content or $page array.

I used global operation such as

global $content;
dpm ($content);

or

global $page;
dpm($page);

But both of these blocks return no result.

Please guide me.

Thanks a lot.

3
  • Why do you need to access the $content? What data do you need from this variable?
    – Shyghar
    Commented Dec 2, 2013 at 15:07
  • I want to access and manipulate comment of a current node.
    – Mehrdad201
    Commented Dec 2, 2013 at 15:28
  • You need to that in hook_node_view() or hook_comment_view(), a random block doesn't have access to that data
    – Clive
    Commented Dec 2, 2013 at 15:40

1 Answer 1

1

If you need to extract the comment of a node and put it in a block you can achieve this with a view.

Create a new view who show 'Comments' and create a block. Now you can add a contexual filter:

Comment: Nid The node ID to which the comment is a reply to.

After that select 'Provide default value' and 'Content ID from URL'

Now you can add a 'Validation criteria' and select 'Content' and check only the content type you want with this block. now set 'Action to take if filter value does not validate' to 'Hide view'

Now you can add this block to a region in the block page and you have the node's comment displayed in a block.

Let me know if this will work for you ^^

7
  • If I use view to make a block of comments (for special node) , are comment links such as "add new comment" or "sign up or login to write a comment" can be rendered in view result ?
    – Mehrdad201
    Commented Dec 2, 2013 at 17:14
  • It is already there in comment section. No need to render those links seprately. What kind of customization you want?
    – Cool
    Commented Dec 2, 2013 at 17:27
  • If you render the entries like 'Comments' you have the default comments display and you can customize that through comment.tpl.php
    – Shyghar
    Commented Dec 2, 2013 at 18:00
  • I found that module.. I don't know if it can help you... drupal.org/project/node_comment_block
    – Shyghar
    Commented Dec 2, 2013 at 18:00
  • thanks. I will try it. but what is your idea about "commentsblock-7.x-2.2.tar.gz" module?
    – Mehrdad201
    Commented Dec 2, 2013 at 18:23

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.