Showing posts with label redirect. Show all posts
Showing posts with label redirect. Show all posts

Thursday, May 21, 2015

Drupal template redirect

I have faced one challenge recently where we need to redirect from one custom node template to another one template.
  • Created one template for custom content type (nature).
  • node--nature.tpl.php
  • node--my_nature.tpl.php (if your content type - my_nature: some time you will face this situation.)
  • This content type has one taxonomy reference.
  • For particular taxonomy reference(condition), we need to display different appearance (layout).
  • So done below fix to redirect for different tpl.
When ever you visit nature content, you will be landed on node--nature.tpl.php.
Inside this tpl, I have used below condition to use different tpl file.

Example:
// Write below code inside node--natute.tpl.php on top of the file.
if (condition) {
 print theme('use_different_layout', array('node' => $node)); // pass argument if you need.
}
// Create different tpl file for "use_different_layout" theme by using hook_theme().

hook_theme() example.
function hook_theme() {
return array(
    'use_different_layout' => array(
      'variables' => array('node' => array()),
      'template' => 'templates/different-layout.tpl.php',
    ),
  );
}


Saturday, April 20, 2013

Drupal 7 drupal_goto options query and fragment



Lets we take example url as " product?a=1&b=2#bottom ". Then you should make drupal_goto as below.

API :
drupal_goto($path = '', array $options = array(), $http_response_code = 302)

Explanation as per example url
$path = 'product'
$options = array( 'query' => array('a' =>1,'b'=>2), 'fragment' => 'bottom', );
$http_response_code is optional (described below).
Ex:
drupal_goto($path ,$options); Will produce " product?a=1&b=2#bottom "
More info about response code,

$http_response_code: (optional) The HTTP status code to use for the redirection, defaults to 302. The valid values for 3xx redirection status codes are defined in RFC 2616and the draft for the new HTTP status codes:

301: Moved Permanently (the recommended value for most redirects).
302: Found (default in Drupal and PHP, sometimes used for spamming search engines).
303: See Other.
304: Not Modified.
305: Use Proxy.
307: Temporary Redirect.