Note: You are currently viewing documentation for Moodle 1.9. Up-to-date documentation for the latest stable version is available here: Header logo.

Header logo: Difference between revisions

From MoodleDocs
(themescrapbook category)
No edit summary
 
(23 intermediate revisions by 9 users not shown)
Line 1: Line 1:
== Introduction ==
{{Scrapbook}}


=== The Goal: your logo in the page header ===
To show your '''logo in the page header''', the file ''header.html'' in your theme folder requires editing.


Your theme shows your logo in the page header.
In the file ''header.html'' you see the following lines (or similar):


=== The Task: change header.html in your theme folder ===
<code php n>
<?php if ($home) { 
// This is what gets printed on the home page only 
?>
  <div id="header-home">
    <div class="headermain"><?php echo $heading ?></div>
    <div class="headermenu"><?php echo $menu ?></div>
  </div>
<?php } else if ($heading) { 
// This is what gets printed on any other page with a heading
?>
  <div id="header">
    <div class="headermain"><?php echo $heading ?></div>
    <div class="headermenu"><?php echo $menu ?></div>
  </div>
<?php } ?>
</code>


You place your logo in the file "header.html" in your theme folder and adjust the appropriate CSS properties.
The following code example shows a part from a header file with a logo. Please replace lines 5 and 12 above with lines 5 and 12 from the code example below. In particular, pay close attention to the following statement:


=== The Way: change the following lines ===
; RIGHT
<code php>
<?php echo $CFG->httpswwwroot.'/theme/'.current_theme() ?>/image.jpg
</code>


In the file "header.html" you see the following lines (or something similar):
Some theme designers have mistakenly used:
; WRONG


<pre>
  <?php echo "$CFG->wwwroot/theme/$CFG->theme/image.jpg" ?>  
01: <?php if ($home) {  
02: // This is what gets printed on the home page only 
03: ?>
04:  <div id="header-home">
05:    <div class="headermain"><?php echo $heading ?></div>
06:    <div class="headermenu"><?php echo $menu ?></div>
07:  </div>
08: <?php } else if ($heading) { 
09: // This is what gets printed on any other page with a heading
10: ?>
11:  <div id="header">
12:    <div class="headermain"><?php echo $heading ?></div>
13:    <div class="headermenu"><?php echo $menu ?></div>
14:  </div>
15: <?php } ?>
</pre>


The following code example shows a part from a header file with a logo. Please replace lines 5 and 12 above with lines 5 and 12 from the code example below.


<pre>
Using $CFG->theme gets the path for the site's default theme rather than the currently selected one. As a result, logos do not appear because they are not in the specified directory. $CFG->wwwroot images throw unsecure warning in IE when using loginhttps.
01: <?php if ($home) { 
02: // This is what gets printed on the home page only 
03: ?>
04:  <div id="header-home">
05:    <div class="headermain"><img src="<?php echo
        $CFG->wwwroot.'/theme/'.current_theme() ?>/pix/big_logo.gif" width="300"
        height="100" alt="mycompany" title="mycompany" id="logo" /></div>
06:    <div class="headermenu"><?php echo $menu ?></div>
07:  </div>
08: <?php } else if ($heading) { 
09: // This is what gets printed on any other page with a heading
10: ?>
11:  <div id="header">
12:    <div class="headermain"><img src="<?php echo
        $CFG->wwwroot.'/theme/'.current_theme() ?>/pix/small_logo.gif" width="210"
        height="70" alt="mycompany" title="mycompany" id="logo" /></div>
13:    <div class="headermenu"><?php echo $menu ?></div>
14:  </div>
15: <?php } ?>
</pre>


Moodle offers one header for all pages and a different header for the start = home page. You can for example make the header for your start page higher and place a bigger logo on it.
<code php n>
<?php if ($home) { 
// This is what gets printed on the home page only 
?>
<div id="header-home">
    <div class="headermain"><img src="<?php echo
      $CFG->themewww.'/'.current_theme() ?>/pix/big_logo.gif" width="300"
        height="100" alt="mycompany" title="mycompany" id="logo" />
    </div>
    <div class="headermenu"><?php echo $menu ?></div>
</div>
<?php } else if ($heading) { 
// This is what gets printed on any other page with a heading
?>
<div id="header">
  <div class="headermain"><img src="<?php echo
        $CFG->themewww.'/'.current_theme() ?>/pix/small_logo.gif" width="210"
        height="70" alt="mycompany" title="mycompany" id="logo" />
  </div>
  <div class="headermenu"><?php echo $menu ?></div>
</div>
<?php } ?>
</code>


The logo position in the page header is defined in the CSS file "styles_layout.css". Please change the values for the CLASS ".headermain" and eventually for the IDs "#header" and "#header-home" if needed. You find the definitions in the section "header" of the CSS file.  
Moodle offers one header for all pages and a different header for the front/home page. You may, for example, make the header for your front page higher and place a bigger logo on it.


'''A tip for a fast jump to the header section of the CSS file:''' Select and copy the word "header" in the section list at the beginning of the file. Then call find in your program and paste "header" into the search dialog. After you click "find" in your dialog your program will find the start of the header section.
The logo position in the page header is defined in the CSS file ''styles_layout.css''. Please change the values for the CLASS <code>.headermain</code> and eventually for the IDs <code>#header</code> and <code>#header-home</code> if needed. You can find the definitions in the section header of the CSS file.  


--[[User:UrsHunkler|UrsHunkler]] 4 November 2005 08:47 (WST)
'''A tip for a fast jump to the header section of the CSS file:''' Select and copy the word "header" in the section list at the beginning of the file. Then call find in your program and paste "header" into the search dialogue. After you click "find" in your dialogue your program will find the start of the header section.


[[Category:ThemeScrapbook]]
===Use an image from your Course files===
<code php n>
<div class="headermain">
  <img src="<?php if (file_exists("$CFG->dataroot/$COURSE->id/header.png"))
    { echo "$CFG->httpswwwroot/file.php/$COURSE->id/header.png"; } ?>" width="210"
    height="70" alt="mycompany" title="mycompany" id="logo" />
</div>
</code>
 
Or even have your own custom CSS override the theme's CSS rules, When it is placed inside the Course's files folder. see MDL-20590
 
== See also: ==
* [[Themes FAQ]]
* [[CSS FAQ]]
 
[[Category:Administrator]]
[[Category:Developer]]
[[Category:Themes]]

Latest revision as of 21:07, 8 April 2011

To show your logo in the page header, the file header.html in your theme folder requires editing.

In the file header.html you see the following lines (or similar):

<?php if ($home) { // This is what gets printed on the home page only ?>

<?php echo $heading ?>
<?php echo $menu ?>

<?php } else if ($heading) { // This is what gets printed on any other page with a heading ?>

<?php } ?>

The following code example shows a part from a header file with a logo. Please replace lines 5 and 12 above with lines 5 and 12 from the code example below. In particular, pay close attention to the following statement:

RIGHT

<?php echo $CFG->httpswwwroot.'/theme/'.current_theme() ?>/image.jpg

Some theme designers have mistakenly used:

WRONG
<?php echo "$CFG->wwwroot/theme/$CFG->theme/image.jpg" ?> 


Using $CFG->theme gets the path for the site's default theme rather than the currently selected one. As a result, logos do not appear because they are not in the specified directory. $CFG->wwwroot images throw unsecure warning in IE when using loginhttps.

<?php if ($home) { // This is what gets printed on the home page only ?>

<img src="<?php echo
      $CFG->themewww.'/'.current_theme() ?>/pix/big_logo.gif" width="300" 
       height="100" alt="mycompany" title="mycompany" id="logo" />
<?php echo $menu ?>

<?php } else if ($heading) { // This is what gets printed on any other page with a heading ?>

<?php } ?>

Moodle offers one header for all pages and a different header for the front/home page. You may, for example, make the header for your front page higher and place a bigger logo on it.

The logo position in the page header is defined in the CSS file styles_layout.css. Please change the values for the CLASS .headermain and eventually for the IDs #header and #header-home if needed. You can find the definitions in the section header of the CSS file.

A tip for a fast jump to the header section of the CSS file: Select and copy the word "header" in the section list at the beginning of the file. Then call find in your program and paste "header" into the search dialogue. After you click "find" in your dialogue your program will find the start of the header section.

Use an image from your Course files

 <img src="<?php if (file_exists("$CFG->dataroot/$COURSE->id/header.png")) 
   { echo "$CFG->httpswwwroot/file.php/$COURSE->id/header.png"; } ?>" width="210" 
   height="70" alt="mycompany" title="mycompany" id="logo" />

Or even have your own custom CSS override the theme's CSS rules, When it is placed inside the Course's files folder. see MDL-20590

See also: