in drupal 7, writing php inside front page module, say:
$page = include_once "templates/page.php"; i put "templates/page.php" under /sites/all/modules/front , drupal complains file missing. suggestion best put files included?
then, after installing php simple html dom parser, wrote following
$html = new simple_html_dom(); and complained class 'simple_html_dom' not found. have tried duplicating library file same folder , home, cases not working. how set correct path?
many thanks.
how include file?
method 1
you place file anywhere under web-root folder folder index.php file (home folder).
$type = 'module'; $name_of_module = 'custom_module'; $path = drupal_get_path($type, $name_of_module); include_once($path . 'custom_file.inc.php'); the valid types listed:
- module
- theme
- profile
- theme_engine
module name filename of .info file in modules folder. read more drupal_get_path()
method 2
to include file existing module should use: module_load_include('inc', 'content', 'includes/content.node_form');
how include template file?
better place template files theme folder because others expect templates files there.
read more template naming suggestions.
but if template has no sense without custom module place template file within custom module folder.
to attach template in theme should use:
function mytheme_preprocess_page(&$variables, $hook) { if (array_key_exists('node', $variables)) { if ($variables['node']->type == 'article'){ $variables['theme_hook_suggestions'][] = 'page__article'; } } } to attach template in module:
/** * implements hook_theme(). */ function module_theme($existing, $type, $theme, $path) { return array ( 'node__contenttype' => array ( 'variables' => array( . . . ), 'template' => 'node--contenttype' , 'base hook' => 'node', 'path' => drupal_get_path('module', 'custom_module'), ), ); } template file should named node--contenttype.tpl.php , placed under custom_module folder.
do not forget clear cache.
Comments
Post a Comment