Jump to content

Anyone Have Any Ideas With Theme Switcher


JNdev

Recommended Posts

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

Link to comment
Share on other sites

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 ========= */

 

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...