I have some custom nodes and I need some blocks to appear depending on node-type. My approach to solve the problem was replicate "/node/$nid" behavior to "/my-type1/$nid" in order to make blocks visible depending on node-type. If a user entered a view to "/node/$nid" he got "drupal_goto" to the right url. My problem now is that for some node-types /type/$nid works, but /node/$nid stopped working; any hint? I am completely lost right now. == hook_nodeapi == ..... case 'view': if ((arg(0)=='node')&&(arg(1)==$node->nid)) { switch ($node->type) { case 'my-type1': case 'my-type2': drupal_goto($node->type.substr($_GET['q'],4)); break; ..... == hook_menu == ...... foreach($node_types AS $key) { $items[$key.'/%node'] = array( 'title callback' => 'node_page_title', 'title arguments' => array(1), 'page callback' => 'node_page_view', 'page arguments' => array(1), 'access callback' => 'node_access', 'access arguments' => array('view', 1), 'file' => 'node.module', 'file path' => drupal_get_path('module', 'node'), 'type' => MENU_CALLBACK, ); $items[$key.'/%node/view'] = array( 'title' => 'View', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); ...... -- *Les normes hi són perquè hi pensis abans de saltar-te-les *La vida és com una taronja, què esperes a exprimir-la? *Si creus que l'educació és cara, prova la ignorància. *La vida és com una moneda, la pots gastar en el que vulguis però només una vegada. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
Your current approach is heading towards a world of hurt. Why not just use PHP for your block visibility? <?php if ($node = menu_get_object()) { return in_array($node->type, array('my-type1', 'my-type2')); } ?> Dave Reid dave@davereid.net On Wed, Jan 27, 2010 at 5:09 AM, Lluís <enboig@gmail.com> wrote:
I have some custom nodes and I need some blocks to appear depending on node-type.
My approach to solve the problem was replicate "/node/$nid" behavior to "/my-type1/$nid" in order to make blocks visible depending on node-type. If a user entered a view to "/node/$nid" he got "drupal_goto" to the right url.
My problem now is that for some node-types /type/$nid works, but /node/$nid stopped working; any hint? I am completely lost right now.
== hook_nodeapi == ..... case 'view': if ((arg(0)=='node')&&(arg(1)==$node->nid)) { switch ($node->type) { case 'my-type1': case 'my-type2': drupal_goto($node->type.substr($_GET['q'],4)); break; .....
== hook_menu == ...... foreach($node_types AS $key) { $items[$key.'/%node'] = array( 'title callback' => 'node_page_title', 'title arguments' => array(1), 'page callback' => 'node_page_view', 'page arguments' => array(1), 'access callback' => 'node_access', 'access arguments' => array('view', 1), 'file' => 'node.module', 'file path' => drupal_get_path('module', 'node'), 'type' => MENU_CALLBACK, ); $items[$key.'/%node/view'] = array( 'title' => 'View', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); ......
-- *Les normes hi són perquè hi pensis abans de saltar-te-les *La vida és com una taronja, què esperes a exprimir-la? *Si creus que l'educació és cara, prova la ignorància. *La vida és com una moneda, la pots gastar en el que vulguis però només una vegada. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
I have used your solution to show blocks for some custom contents, and works ok for "node/19550" but fails on "node/19550/clients" or when there text attached after nid. Any hint? 2010/1/27 Dave Reid <dave@davereid.net>:
Your current approach is heading towards a world of hurt. Why not just use PHP for your block visibility?
<?php if ($node = menu_get_object()) { return in_array($node->type, array('my-type1', 'my-type2')); } ?>
Dave Reid dave@davereid.net
On Wed, Jan 27, 2010 at 5:09 AM, Lluís <enboig@gmail.com> wrote:
I have some custom nodes and I need some blocks to appear depending on node-type.
My approach to solve the problem was replicate "/node/$nid" behavior to "/my-type1/$nid" in order to make blocks visible depending on node-type. If a user entered a view to "/node/$nid" he got "drupal_goto" to the right url.
My problem now is that for some node-types /type/$nid works, but /node/$nid stopped working; any hint? I am completely lost right now.
== hook_nodeapi == ..... case 'view': if ((arg(0)=='node')&&(arg(1)==$node->nid)) { switch ($node->type) { case 'my-type1': case 'my-type2': drupal_goto($node->type.substr($_GET['q'],4)); break; .....
== hook_menu == ...... foreach($node_types AS $key) { $items[$key.'/%node'] = array( 'title callback' => 'node_page_title', 'title arguments' => array(1), 'page callback' => 'node_page_view', 'page arguments' => array(1), 'access callback' => 'node_access', 'access arguments' => array('view', 1), 'file' => 'node.module', 'file path' => drupal_get_path('module', 'node'), 'type' => MENU_CALLBACK, ); $items[$key.'/%node/view'] = array( 'title' => 'View', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); ......
-- *Les normes hi són perquè hi pensis abans de saltar-te-les *La vida és com una taronja, què esperes a exprimir-la? *Si creus que l'educació és cara, prova la ignorància. *La vida és com una moneda, la pots gastar en el que vulguis però només una vegada. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
-- *Les normes hi són perquè hi pensis abans de saltar-te-les *La vida és com una taronja, què esperes a exprimir-la? *Si creus que l'educació és cara, prova la ignorància. *La vida és com una moneda, la pots gastar en el que vulguis però només una vegada. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
Hi You could use the arg function with the php block visibility - or - use the context module for a gui based approach. <?php $my_types = array('type1', 'type2'); return (arg(0) == 'node' && is_numeric(arg(1)) && ($node = node_load(arg(1)) && in_array($node->type, $my_types)) ?> Lee On Wed, 17 Mar 2010 16:25:31 +0100, Lluís Forns <enboig@gmail.com> wrote:
I have used your solution to show blocks for some custom contents, and works ok for "node/19550" but fails on "node/19550/clients" or when there text attached after nid.
Any hint?
2010/1/27 Dave Reid <dave@davereid.net>:
Your current approach is heading towards a world of hurt. Why not just use PHP for your block visibility?
<?php if ($node = menu_get_object()) { return in_array($node->type, array('my-type1', 'my-type2')); } ?>
Dave Reid dave@davereid.net
On Wed, Jan 27, 2010 at 5:09 AM, Lluís <enboig@gmail.com> wrote:
I have some custom nodes and I need some blocks to appear depending on node-type.
My approach to solve the problem was replicate "/node/$nid" behavior to "/my-type1/$nid" in order to make blocks visible depending on node-type. If a user entered a view to "/node/$nid" he got "drupal_goto" to the right url.
My problem now is that for some node-types /type/$nid works, but /node/$nid stopped working; any hint? I am completely lost right now.
== hook_nodeapi == ..... case 'view': if ((arg(0)=='node')&&(arg(1)==$node->nid)) { switch ($node->type) { case 'my-type1': case 'my-type2': drupal_goto($node->type.substr($_GET['q'],4)); break; .....
== hook_menu == ...... foreach($node_types AS $key) { $items[$key.'/%node'] = array( 'title callback' => 'node_page_title', 'title arguments' => array(1), 'page callback' => 'node_page_view', 'page arguments' => array(1), 'access callback' => 'node_access', 'access arguments' => array('view', 1), 'file' => 'node.module', 'file path' => drupal_get_path('module', 'node'), 'type' => MENU_CALLBACK, ); $items[$key.'/%node/view'] = array( 'title' => 'View', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); ......
-- *Les normes hi són perquè hi pensis abans de saltar-te-les *La vida és com una taronja, què esperes a exprimir-la? *Si creus que l'educació és cara, prova la ignorància. *La vida és com una moneda, la pots gastar en el que vulguis però només una vegada. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
Why don't you just use Context? ----- Cameron Eagans Owner, Black Storms Studios, LLC http://www.blackstormsstudios.com On Wed, Jan 27, 2010 at 4:09 AM, Lluís <enboig@gmail.com> wrote:
I have some custom nodes and I need some blocks to appear depending on node-type.
My approach to solve the problem was replicate "/node/$nid" behavior to "/my-type1/$nid" in order to make blocks visible depending on node-type. If a user entered a view to "/node/$nid" he got "drupal_goto" to the right url.
My problem now is that for some node-types /type/$nid works, but /node/$nid stopped working; any hint? I am completely lost right now.
== hook_nodeapi == ..... case 'view': if ((arg(0)=='node')&&(arg(1)==$node->nid)) { switch ($node->type) { case 'my-type1': case 'my-type2': drupal_goto($node->type.substr($_GET['q'],4)); break; .....
== hook_menu == ...... foreach($node_types AS $key) { $items[$key.'/%node'] = array( 'title callback' => 'node_page_title', 'title arguments' => array(1), 'page callback' => 'node_page_view', 'page arguments' => array(1), 'access callback' => 'node_access', 'access arguments' => array('view', 1), 'file' => 'node.module', 'file path' => drupal_get_path('module', 'node'), 'type' => MENU_CALLBACK, ); $items[$key.'/%node/view'] = array( 'title' => 'View', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); ......
-- *Les normes hi són perquè hi pensis abans de saltar-te-les *La vida és com una taronja, què esperes a exprimir-la? *Si creus que l'educació és cara, prova la ignorància. *La vida és com una moneda, la pots gastar en el que vulguis però només una vegada. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
To tell de truth: I didn't know about menu_get_object(). I have some views where blocks must be shown also; I suppose I could use arg() there to check the root of the path. And about "Context"; I suppose you mean the module. I hadn't heard of it, but all versions are beta or alpha.... On Wed, Jan 27, 2010 at 4:13 PM, Cameron Eagans <cweagans@gmail.com> wrote:
Why don't you just use Context? ----- Cameron Eagans Owner, Black Storms Studios, LLC http://www.blackstormsstudios.com
On Wed, Jan 27, 2010 at 4:09 AM, Lluís <enboig@gmail.com> wrote:
I have some custom nodes and I need some blocks to appear depending on node-type.
My approach to solve the problem was replicate "/node/$nid" behavior to "/my-type1/$nid" in order to make blocks visible depending on node-type. If a user entered a view to "/node/$nid" he got "drupal_goto" to the right url.
My problem now is that for some node-types /type/$nid works, but /node/$nid stopped working; any hint? I am completely lost right now.
== hook_nodeapi == ..... case 'view': if ((arg(0)=='node')&&(arg(1)==$node->nid)) { switch ($node->type) { case 'my-type1': case 'my-type2': drupal_goto($node->type.substr($_GET['q'],4)); break; .....
== hook_menu == ...... foreach($node_types AS $key) { $items[$key.'/%node'] = array( 'title callback' => 'node_page_title', 'title arguments' => array(1), 'page callback' => 'node_page_view', 'page arguments' => array(1), 'access callback' => 'node_access', 'access arguments' => array('view', 1), 'file' => 'node.module', 'file path' => drupal_get_path('module', 'node'), 'type' => MENU_CALLBACK, ); $items[$key.'/%node/view'] = array( 'title' => 'View', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); ......
-- *Les normes hi són perquè hi pensis abans de saltar-te-les *La vida és com una taronja, què esperes a exprimir-la? *Si creus que l'educació és cara, prova la ignorància. *La vida és com una moneda, la pots gastar en el que vulguis però només una vegada. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
-- *Les normes hi són perquè hi pensis abans de saltar-te-les *La vida és com una taronja, què esperes a exprimir-la? *Si creus que l'educació és cara, prova la ignorància. *La vida és com una moneda, la pots gastar en el que vulguis però només una vegada. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
Yeah, context module. It's beta right now, but it works well (it's a Dev Seed beta, so it's pretty high quality =P ) ----- Cameron Eagans Owner, Black Storms Studios, LLC http://www.blackstormsstudios.com On Wed, Jan 27, 2010 at 8:57 AM, Lluís <enboig@gmail.com> wrote:
To tell de truth: I didn't know about menu_get_object(). I have some views where blocks must be shown also; I suppose I could use arg() there to check the root of the path.
And about "Context"; I suppose you mean the module. I hadn't heard of it, but all versions are beta or alpha....
On Wed, Jan 27, 2010 at 4:13 PM, Cameron Eagans <cweagans@gmail.com> wrote:
Why don't you just use Context? ----- Cameron Eagans Owner, Black Storms Studios, LLC http://www.blackstormsstudios.com
On Wed, Jan 27, 2010 at 4:09 AM, Lluís <enboig@gmail.com> wrote:
I have some custom nodes and I need some blocks to appear depending on node-type.
My approach to solve the problem was replicate "/node/$nid" behavior to "/my-type1/$nid" in order to make blocks visible depending on node-type. If a user entered a view to "/node/$nid" he got "drupal_goto" to the right url.
My problem now is that for some node-types /type/$nid works, but /node/$nid stopped working; any hint? I am completely lost right now.
== hook_nodeapi == ..... case 'view': if ((arg(0)=='node')&&(arg(1)==$node->nid)) { switch ($node->type) { case 'my-type1': case 'my-type2': drupal_goto($node->type.substr($_GET['q'],4)); break; .....
== hook_menu == ...... foreach($node_types AS $key) { $items[$key.'/%node'] = array( 'title callback' => 'node_page_title', 'title arguments' => array(1), 'page callback' => 'node_page_view', 'page arguments' => array(1), 'access callback' => 'node_access', 'access arguments' => array('view', 1), 'file' => 'node.module', 'file path' => drupal_get_path('module', 'node'), 'type' => MENU_CALLBACK, ); $items[$key.'/%node/view'] = array( 'title' => 'View', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); ......
-- *Les normes hi són perquè hi pensis abans de saltar-te-les *La vida és com una taronja, què esperes a exprimir-la? *Si creus que l'educació és cara, prova la ignorància. *La vida és com una moneda, la pots gastar en el que vulguis però només una vegada. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
-- *Les normes hi són perquè hi pensis abans de saltar-te-les *La vida és com una taronja, què esperes a exprimir-la? *Si creus que l'educació és cara, prova la ignorància. *La vida és com una moneda, la pots gastar en el que vulguis però només una vegada. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
Lluís wrote:
I have some custom nodes and I need some blocks to appear depending on node-type.
And yet another option would be to use Panels + Page Manager to provide different layouts at node/% without having to write any custom code at all.
participants (6)
-
Cameron Eagans -
Dave Reid -
Earl Miles -
Lee Rowlands -
Lluís -
Lluís Forns