I recently upgraded my website to Drupal 6. Unfortunately I seem to be missing the clue on how to get access to Drupal core variables from within the front page generated by the front_page.module.

In general php works fine. If I put <?php print 'Hello world!'; ?> inside the front page, Hello World! will show up on the front page just as expected.

If I want the header information to be more dynamic though and put i.g. the line

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language ?>" lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">

in it, the outcome will be

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="" lang="" dir="">

instead of the desired

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="" dir="ltr">

seen with the use of the garland theme.

Also the use of the variables $head_title, $head, $styles, $scripts and mostly desired $search_box will return nothing, even when they are defined as global.

Can somebody put me back on the right track, please? Any help will be greatly appreciated. Thanks.

Comments

Phillip Mc’s picture

this is just a guess, but, you may have to call the init_theme function in your custom front page to make all the variables available.

Try inserting this line at the top:

<?php init_theme(); ?>

Norrin’s picture

Thanks for trying to help, but this doesn't work, I'm afraid.

Dublin Drupaller’s picture

Assigned: Unassigned » Dublin Drupaller

you need to call the variables directly because the front_page.module deliberately bypasses the theme engine and theme so you've got a blank canvas

As an example, to insert your styles into your front_page use the following snippet:

Styles: print drupal_get_css();

Your search form: print drupal_get_form('search_theme_form') ;

Language: print $GLOBALS['locale'];

Site footer: print variable_get('site_footer', '') ;

And so on...

Here's a quick list of variables (from the phptemplate engine):

'base_path'           => base_path(),
    'breadcrumb'          => theme('breadcrumb', drupal_get_breadcrumb()),
    'closure'             => theme('closure'),
    'content'             => $content,
    'feed_icons'          => drupal_get_feeds(),
    'footer_message'      => filter_xss_admin(variable_get('site_footer', FALSE)) . "\n" . $variables['regions']['footer'],
    'head'                => drupal_get_html_head(),
    'head_title'          => implode(' | ', $head_title),
    'help'                => theme('help'),
    'language'            => $GLOBALS['locale'],
    'layout'              => $layout,
    'logo'                => theme_get_setting('logo'),
    'messages'            => theme('status_messages'),
    'mission'             => isset($mission) ? $mission : '',
    'primary_links'       => menu_primary_links(),
    'search_box'          => (theme_get_setting('toggle_search') ? drupal_get_form('search_theme_form') : ''),
    'secondary_links'     => menu_secondary_links(),
    'sidebar_left'        => $sidebar_left,
    'sidebar_right'       => $sidebar_right,
    'site_name'           => (theme_get_setting('toggle_name') ? variable_get('site_name', 'Drupal') : ''),
    'site_slogan'         => (theme_get_setting('toggle_slogan') ? variable_get('site_slogan', '') : ''),
    'css'                 => drupal_add_css(),
    'styles'              => drupal_get_css(),
    'scripts'             => drupal_get_js(),
    'tabs'                => theme('menu_local_tasks'),
    'title'               => drupal_get_title()
Norrin’s picture

Cool, but the use of the variables $GLOBALS['locale'] and implode(' | ', $head_title) are still returning nothing.

Never mind though, I'll find a solution for that too. Most important to me was the dynamic output of the styles-, scripts- and search_box-variables on the front page. This works perfectly now. So you finally brought a long and restless search to a happy ending. ;o)

Thank you ever so much for helping.

Dublin Drupaller’s picture

you're welcome.

not sure why your locale isn't displaying properly but as a tip what might be more efficient for what you're doing would be to copy your page.tpl.php file, call it page-front.tpl.php and edit to suit. Drupal shold automatically pick up that page template file when you upload it to your theme folder. Use THEMED instead of FULL in your front_page module settings page.

That way you have the convenience of using the front page.module to control which content is displayed while also controlling the layout in more detail. also, because you're using the theme engine, your variables should work as expected as well.

hope that helps

dub

Norrin’s picture

That sounds very interesting. I'll give it a try in a quite moment.

Thank you once again.

afterdark’s picture

I couldn't find my front_page module settings page, where is it?
Anyway, the page-front.tpl.php seems to work perfectly, thanks for the tip, D.D.

Scott M. Sanders’s picture

Front settings are at Admin > Site Config > Advanced Front Page Settings (alpha sort may confuse) or just admin/settings/front.

afterdark’s picture

Thanks a lot for the answer, Scott. I haven't noticed that the tread was all about the front page module! Now it's installed and the changes are properly setted.

cazou’s picture

Hi, I can't access $language or $GLOBALS['locale'] either.

Did anyone succeed getting these variables inside the frontpage module using the page_front.tpl.php template ?

cazou’s picture

Ok, actually, it's not $GLOBALS['locale'] but $GLOBALS['language']...

Dublin Drupaller’s picture

Status: Active » Closed (fixed)
knalstaaf’s picture

I'm having exactly the same problem as described in the very first post of this thread. I wasn't able to solve it with the given replies.

My code:

<?php init_theme(); ?>
<?php print $GLOBALS['language']; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language ?>" lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">

Results in: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="" lang="" dir="">

More ideas?

I'm also having trouble using custom includes (which are located in the folder of my theme). Even an include with an absolute link is not working.

knalstaaf’s picture

How do you add regions in Themed-mode? My whole front-page is made in the Advanced front page settings, except for the header (so I made a page-front.tpl.php with a <?php print $content ?>-rule to put the rest of the page in).

This method is not working, since it's meant for D5.x. Is there some documentation for D6.x available about this matter?

P.S.: the region ìs defined in the info-file.