This is an old revision of the document!


Skript in den <head> Bereich

Vorlagen/Template <head> Bereich

Forum: http://forum.phpwcms.org/viewtopic.php?p=101300#p101300 (OG)

Hier wird eine Technik vorgestellt, mit der verschiedene Aufrufe zu JavaScripten oder CSS-Dateien im <head> Bereich nach Bedarf abgelegt werden können. (<head> impfen).

Aus phpwcms heraus werden verschiedene JavaSkripte und CSS-Dateien automatisch abgelegt.

In Templates zu Artikeln oder CPs gibt es häufig den Zwang bestimmte Skripte oder CSS-Dateien mit der Seite zu laden. Bei entsprechendem Skript-Dateiname wird ein doppelter Aufruf vermieden (das Skript oder die CSS-Datei könnte schon vom System geladen worden sein).

Die Prozeduren können auch in einem frontend_render-Skript abgelegt werden.

Der Skript-Dateiname (here: $block['custom_htmlhead']['…script…']) wird immer als Array Index verwendet.

Bsp.:

script into head area

<?php
 
   /* Load my special Mootools script */
   $block['custom_htmlhead']['mootools.js']   = '  <script src="'.TEMPLATE_PATH.'inc_js/mootools/mootools-release-1.11.js" type="text/javascript"></script>';
 
   /* Load Mootools in newer releases */
   initMootools();
 
   /* Load My custom JavaScript */
   $block['custom_htmlhead']['my.js']      = '  <script src="'.TEMPLATE_PATH.'inc_js/my.js" type="text/javascript"></script>';
 
   /* Load some other <head> positions */
   $block['custom_htmlhead']['favicon1']      = '  <link rel="icon" href="favicon.ico" type="image/x-icon" />';
   $block['custom_htmlhead']['favicon2']      = '  <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />';
 
   /* IE <=6 Style Hack */
   $block['custom_htmlhead']['IEhack']  = '  <!--[if lt IE 7]><style type="text/css"> #inner { height:300px; } </style><![endif]-->';
 
   /* Hm I want to overwrite some default CSS */
   $block['custom_htmlhead']['mycss']  = '  <style type="text/css">' . LF . '  <!--' . LF;
   $block['custom_htmlhead']['mycss'] .= '   #header { ' . LF;
   $block['custom_htmlhead']['mycss'] .= '      background: #F9E931 url(template/img/mozilla.png) no-repeat left top !important;' . LF;
   $block['custom_htmlhead']['mycss'] .= '      background: #F9E931 url(template/img/ie.gif) no-repeat left top;' . LF;
   $block['custom_htmlhead']['mycss'] .= '   }';
   $block['custom_htmlhead']['mycss'] .= LF . '  //-->' . LF . '  </style>';
?>


Sonderfall CSS-Datei in /template/inc_css/*

Hierzu gibt es ein eigenes Array ['block']['css'], das direkt das Verzeichnis /template/inc_css/* ansteuert.
Bsp.:

$GLOBALS['block']['css']['reg_tabs_accordion01_login'] = 'specific/reg_tabs_accordion01_login.css';



Modul <head> Bereich

Forum: http://forum.phpwcms.org/viewtopic.php?p=113969#p113969 (breitsch)

Um CSS- oder JS-Dateien in die Frontendeausgabe des Moduls im <head> Bereich einzubinden wird folgender Code hinzugefügt:

script into module head area

// ==== load js functions
$block['custom_htmlhead']['javascript.js'] = '  <script src="'.$phpwcms['modules'][$crow['acontent_module']]['dir'].'template/js/javascript.js" type="text/javascript"></script>';
 
// ==== load inline css
$block['custom_htmlhead']['inlinecss.css'] ='<style type="text/css">'.LF.'  .classname  {property:value;}'.LF.'</style>';
 
// ==== load external style sheet
$GLOBALS['block']['custom_htmlhead']['externalcss.css'] = LF.'  <style type="text/css">'.LF.'@import url("'.$phpwcms['modules'][$crow['acontent_module']]['dir'].'template/css/externalcss.css");'.LF.'</style>';

<note important> Der letzte Eintrag (Schlüssel → siehe Skript-Dateiname oben) muss einzigartig sein.
$block['custom_htmlhead']['…script…'] </note>

deutsch/technik/aufruf-interner-funktionen/skript-in-den-head-bereich.1240639561.txt.gz · Last modified: 2018/06/03 18:06 (external edit)
www.planmatrix.de www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0