0

How do I call a custom theme file (stored in the theme folder) that displays on a specific page that is created by a module.

It's a module for viewing mortgages in a full-page view. The template file is called page--single_view.tpl.php

The module is named single_view and has these functions:

<?php 
/**
 * @file
 * Single Mortgage Views module file
 */

 /**
 * hook_menu() add to menu
 */
 function mortgage_single_view_menu() {

  $items = array();

  $items['mortgage/%/view'] = array(
    'page callback' => 'single_view_theme', //This isn't correct but just set this way for now
    'page argument' => array(3), //pass 3rd argument of url -- 1. drupal 2. mortgage 3. %
    'access callback' => TRUE,
  );

  return $items;
 }

 /*
 * Implementation of hook_theme().
 */

function single_view_theme($existing, $type, $theme, $path){
  return array (
    'page__single_view' => array (
      'variables' => array(),
      'template' => 'page--single_view' ,
      'base hook' => 'page',
      'path' => drupal_get_path('module', 'single_view'),
    ),
  );
}

I'm guessing my implementation of hook_theme isn't correct. The page that comes up is just blank?

4
  • Why is your implementation of hook_menu called mortgage_single_view_menu? If your module is called single_view, then your implementation of hook_menu should be single_view_menu. Also, you're using hook_theme all wrong. It is not meant to be a page callback. Will see if I have time to write up the right way to do it.
    – Aaron
    Commented Aug 12, 2015 at 18:31
  • I corrected that single_view hook_menu. I typed it wrong in here but it was correct in my .module file. Per @gnuget answer below I changed the callback to a callback function which then calls the theme() function and passes it the key and $variables? I'm so confused about how to use these theme hooks lol
    – Exziled
    Commented Aug 12, 2015 at 18:40
  • Work on getting the page callback returning something before you tackle using theme functions properly. Don't make life unnecessarily difficult for yourself. Also: your page argument value should be array(1) if it's your intention to pass the value of the % placeholder to your page callback.
    – Aaron
    Commented Aug 12, 2015 at 18:45
  • The first step should just be getting the page to work at all; try to have your callback just do return array(); Commented Aug 12, 2015 at 18:47

1 Answer 1

0

I think you can't pass the single_view_theme as a page callback.

create a new function with something like this:

function single_view_callback($something) {
  return theme('page__single_view', $variables);
}

And in your page callback replace 'single_view_theme' with 'single_view_callback'.

3
  • Hmmmm so it's still coming up as a blank page (cleared the caches just incase). Should I keep my hook_theme() function in there as is?
    – Exziled
    Commented Aug 12, 2015 at 18:28
  • I tried to add the callback function but the page still comes up blank after clearing caches.
    – Exziled
    Commented Aug 12, 2015 at 18:37
  • 2
    Blank pages can be caused by errors; make sure you've taken the steps you need to take to make them visible. Easiest way is adding these lines to index.php: (from: drupal.org/node/158043) error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); The recommendations by Gnuget should be working (assuming you did not copy-paste them exactly). Commented Aug 12, 2015 at 18:42

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.