0

I want to give the path for custom page tpl which I have created for specific content type. 'test_insights' is my content type name.I have created custom page tpl in the folder

project_name/themes/themename/templates/page--test_insights.tpl.php

I want to know how to give the path for created tpl now I tried http://localhost/project_name/test_insights

I caught the error as

The requested page "/project_name/test_insights" could not be found

.

2

If I understood your question correctly, you are looking for hook_menu. You can find the API here.

An Example:

function mymodule_menu() {
    $items['test_insights'] = array(
      'page callback' => 'mymodule_test_insights',
      'page arguments' => array(),
    );
    return $items;
  }

//The callback function
function mymodule_test_insights(){
    //Do the necessary actions
    return $something;
}

Note: After implementing the hook_menu you have to clear the drupal cache to access the URL.

To add content type specific page tpl you have to use theme_hook_suggestions by implementing template_preprocess_page. You can add the below code in the template.php file of your theme

Example:

function themeName_preprocess_page(&$vars, $hook) { //themeName change to your theme name
  if (isset($vars['node'])) {
  // If the node type is "test_insights" the template suggestion will be "page--test--insights.tpl.php".
   $vars['theme_hook_suggestions'][] = 'page__'. str_replace('_', '--', $vars['node']->type);
  }
}
| improve this answer | |
  • I'm newbiee.can you give some url suggestion to custom page tpl for specific content type – user3386779 Jan 18 '17 at 6:39
  • @user3386779, updated the answer. – James Jan 18 '17 at 6:49
  • where to write function mymodule_menu() { $items['test_insights'] = array( 'page callback' => 'mymodule_test_insights', 'page arguments' => array(), ); return $items; } //The callback function function mymodule_test_insights(){ //Do the necessary actions return $something; } – user3386779 Jan 18 '17 at 6:56
  • You have to create a module for that. And inside the .module file you can write it. – James Jan 18 '17 at 7:01
  • can you give one example – user3386779 Jan 18 '17 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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