I have created module.I want to display the images and my text on my custom page with my own style.How to display the images and text?

Comments

sandeep.kumbhatil’s picture

If you have created the custom module, you can create a menu item and callback in which you can call a theme function using
hook_theme

function menu_callback_function(){
return theme('THEMENAME');
}
/**
 * Implements hook_theme()
 */
function YOURMODULE_theme() {
    return array(
        'THEMENAME' => array(
       	 'render element' => 'elements',
            'template' => 'templates/YOUR_TPL_FILE',
        ),
    );
} 

You can place tpl file in your module folder, In tpl file you can render the image and text.

Hope this will help you.

Nithyanantham’s picture

Thank sir for response.I am beginner for module development.i have doubt in template file creation.how to create template and if i want to create template what are the functions i want to use in the .module file.If I created template file for the particular page how its identify this template file for this page????

sandeep.kumbhatil’s picture

For your better understanding let me put down the code in detail, hope this will help you. For creating a page you can create a menu item using hook_menu

/**
* Implements hook_menu()
*/
function YOURMODULE_menu() {
    $items['menu_url'] = array(
      'page callback' => 'menu_callback_function',
    );
    return $items;
}

To create a template file you first need to register the theme using hook_theme, you can keep (YOUR_TPL_FILE.tpl.php) file in your module folder and place under templates folder.

/**
 * Implements hook_theme()
 */
function YOURMODULE_theme() {
    return array(
        'THEMENAME' => array(
            'render element' => 'elements',
            'template' => 'templates/YOUR_TPL_FILE',
        ),
    );
}

Menu item will call below function, In which you are calling the registered theme which in turn refer to the template file.

function menu_callback_function(){
return theme('THEMENAME');
}
Nithyanantham’s picture

how to change the full layout for single page??I have created simple theme.how can i use the theme for the single page of my site??
pls help me.

sandeep.kumbhatil’s picture

I think you can use hook_preprocess_page

function mymodule_preprocess_page(&$variables, $hook) {
  if ( my_condition() ) {
    $variables['theme_hook_suggestions'][] = 'your_page';
  }
}
khyati_clarion’s picture

After specifying theme suggestion, you need to create template file with the same name. In name of theme suggestion one needs to replace "_" with "-" while creating template, e.g. maintenance-page.tpl.php

jaypan’s picture

I already told you how to do this in your other thread: https://www.drupal.org/node/2341187

Contact me to contract me for D7 -> D10/11 migrations.