Copy Source | Copy HTML <?php head::addCSS( 'main' ) ?>
Copy Source | Copy HTML
- <? php
- / * <br/> * Helper accumulates the inserted css and js files. <br/> * And at the end inserts them into the layout. <br/> * /
- / ** <br/> * Insert style and javascript files <br/> * <br/> * @author Valera Sizov <br/> * /
- class head
- {
- static $ styleFiles = array ();
- static $ jsFiles = array ();
- static public function addingFiles ( $ layout )
- {
- $ css = array_merge (Kohana :: config ( 'style.files' ), self :: $ styleFiles );
- $ js = array_merge (Kohana :: config ( 'js.files' ), self :: $ jsFiles );
- $ out = '' ;
- foreach ( $ css as $ file )
- {
- $ out . = '<link rel = "stylesheet" type = "text / css" href = "/ static / css /' . $ file . '.css">' . "\ n" ;
- }
- foreach ( $ js as $ file )
- {
- $ out . = '<script src = "/ static / js /' . $ file . '.js" type = "text / javascript"> </ script>' . "\ n" ;
- }
- return str_replace ( '</ head>' , '$ out. "\ n". </ head>' , $ layout );
- }
- static public function addCss ( $ css )
- {
- if (is_array ( $ css )) {
- self :: $ styleFiles = array_merge (self :: $ styleFiles , $ css );
- } else {
- self :: $ styleFiles = array_merge (self :: $ styleFiles , array ( $ css ));
- }
- }
- static public function addJs ( $ js )
- {
- if (is_array ( $ js )) {
- self :: $ jsFiles = array_merge (self :: $ jsFiles , $ js );
- } else {
- self :: $ jsFiles = array_merge (self :: $ jsFiles , array ( $ js ));
- }
- }
- static public function removeCss ()
- {
- Kohana :: config_set ( 'style.files' , array ());
- }
- static public function removeJs ()
- {
- Kohana :: config_set ( 'js.files' , array ());
- }
- static public function addOnlyCss ( $ css )
- {
- self :: removeCss ();
- self :: addCss ( $ css );
- }
- static public function addOnlyJs ( $ js )
- {
- self :: removeJs ();
- self :: addJs ( $ js );
- }
- }
- ?>
Copy Source | Copy HTML
- <? php
- abstract class BaseController extends Template_Controller {
- public $ template = 'frontend / layout' ;
- public function _render ()
- {
- if ( $ this -> auto_render == TRUE)
- {
- // Render the template when the class is destroyed
- echo head :: addingFiles ((string) $ this -> template);
- // $ this-> template-> render (TRUE);
- }
- }
- }
- ?>
Copy Source | Copy HTML
- <? php
- / * Enumeration of javascript files that will be attached to the main template by default <br/> then you can override them or add them * /
- $ config [ 'files' ] = array ();
- ?>
Copy Source | Copy HTML
- <? php
- / * Enumeration of javascript files that will be attached to the main template by default <br/> then you can override them or add them * /
- $ config [ 'files' ] = array ();
- ?>
Copy Source | Copy HTML
- <? php head :: addCss ( 'form_contacts' ) ?>
Source: https://habr.com/ru/post/61894/
All Articles