Hello, could please anybody help me?
I want to create block which will display same content as is displayed at current page.

Comments

sadnan’s picture

May be if you some how save the node number of current page in the drupal table then you can display the content by writing php code in the block which you reserved for displaying the page content.

--------------------code to put in block------------------------

$node_number = get_variable('current_page_node_num');

$node = node_load($node_number) //retreive from variable table
echo $node->body;

Now the question is how to find the node number of current page???

You can put some code in node_access() function of node.module to save the current page number
--------------------code to be put in the node_access() function----------------

set_variable('current_page_node_num ', $node->nid);

I am not sure abt. the usage of set and get variable which basically create a new vaibale 'current_page_link' inside the drupal ---variable----table. Once you have the current number you can use it to display content in the block.

svihel’s picture

I'm tried that and system replied message "Fatal error: Call to undefined function set_variable() in C:\wamp\www\drupal\modules\node\node.module on line 2645".
Could you please tell me where and how exactly may I define that function to make it work?

sadnan’s picture

I could not give u enough info. on set and get varaible. Sorry mate.

These functions are variable_get() & variable_set()

I was working with this set and get varible and I found it in some forum. Search in the forum. Basically set and get variable are two functions which will store a variable along with values in database of drupal. YOu can easiy find it.

variable_set('current_page_id', $node->nid);
//make sure the above variable name is unique i.e current_page_id

$id = variable_get('current_page_id','');

Markus Sandy’s picture

The above approach will get/set a variable that is global to the site, whereas the "current page" is a per user concept.

An alternative approach is to use the arg() function to see if the current page url contains an id number.

To try this out, just add a new block using the following PHP:

if ((arg(0) == "node") && (arg(1) > 0)) {
  $node = node_load(array("nid" => arg(1)));
  if ($node)
    print $node->title;
}

This will display only on pages of the form node/123 (even if you have redefined the path for some nodes).

---
Markus Sandy
http://Ourmedia.org

svihel’s picture

Thanks for tip. It's very helpfull i have made few changes to support URL aliases too and it really works :-)
Going to do some testing tho, just to be sure it works in all cases with my changes.

Actually I didn't even hope anyone would answer my after this topic goes down. So this is pleasent surprise for me :-)