Jump to content

Anyone Have Any Ideas With Theme Switcher


Recommended Posts

Posted

I have this code but not work and place on client controller, suggestion from my friend naja7 aka @Blesta Addons

I mean can switch theme from browser Eg domain.com/?theme=bootstrap-1, domain.com/?theme=bootstrap-2 etc

 

/*===================== Theme Switcher ========= */	



$style = null;
$stylesArr = array('bootstrap', 'theme-1', 'theme-2', 'theme-3');

 // Get from URL as override
  if(isset($_GET['theme']) && isset($stylesArr[$_GET['theme']])) {
    $style = 'client/' . $_GET['theme'];
  }

 // Fallback condition Set Default Theme
  if (empty($style)) {
   $style = 'client/bootstrap'; //Set Back To Default Theme
  }

 // Get from cookie
  if(isset($_COOKIE['theme']) && isset($stylesArr[$_COOKIE['theme']])) {
    $style = 'client/' . $_COOKIE['theme'];
  }
  
  // Update cookie
    $expiration = time() + 60 * 60; // Expire in 1 hour
    setcookie('theme', $style, $expiration);


// Set Theme For Blesta
$this->setDefaultView($style);
		

		
/* =================== Theme Switcher ========= */	

 

All help are welcome and greatly appreciated

Posted

Hello try this code .

Open app/client_controller.php

under parent::preAction(); add the fallowing code

		/*===================== Theme Switcher ========= */	
		if (!isset($this->Session)) {
			Loader::loadComponents($this, ["Session"]);
		}

		if (isset($_GET['switcher']) ) {
			$this->Session->write("blesta_theme", $_GET['switcher']);				
		}		
		
		if ($this->Session->read('blesta_theme')) {
			$theme = $this->Session->read('blesta_theme');
			// Set the THEME
			$this->setDefaultView("client/". $theme); 			
		}
		/* =================== Theme Switcher ========= */

 

Posted

Wow, it works well with

		if (!isset($this->Session)) {
			Loader::loadComponents($this, ["Session"]);
		}



Thank you sir naja7, this is very helpful to me, although it can not be on all pages.

Posted
On 18/11/2016 at 6:35 PM, Jawanet said:

Wow, it works well with


		if (!isset($this->Session)) {
			Loader::loadComponents($this, ["Session"]);
		}



Thank you sir naja7, this is very helpful to me, although it can not be on all pages.

Is only limited to client pages and maybe also for logged in client only .

but if blesta make the theme set via configure , then it will be available for all .

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...