HansSchouten / PHPageBuilder

A drag and drop page builder to manage pages in any PHP project
https://www.phpagebuilder.com
MIT License
739 stars 180 forks source link

I need to set active theme dynamically on Runtime, but it does not work right. #94

Open Nitinkumarwis opened 3 years ago

Nitinkumarwis commented 3 years ago

I have 4 different templates with different css/js. I need to set active theme dynamically on runtime in config pagebuilder. but they does not work. It constantly pick first template css/js. Please help me out from this ASAP.

HansSchouten commented 3 years ago

After changing the pagebuilder config (to change the theme > active_theme) dynamically you have to create a new pagebuilder instance:

// $config change here
$builder = new PHPageBuilder\PHPageBuilder($config);
Nitinkumarwis commented 3 years ago

Its not working i am doing like :

config(['pagebuilder.theme.active_theme' => 'template-four']); $builder = new PHPageBuilder\PHPageBuilder(config('pagebuilder'));

It is always rendering the CSS of that template which is given in the Pagebuilder config file.

HansSchouten commented 3 years ago

When I do:

config(['pagebuilder.theme.active_theme' => 'template-four']);
$pageBuilder = new PHPageBuilder(config('pagebuilder'));
$pageBuilder->handlePublicRequest();

It works just fine (I get an error that this theme does not exist in my case). Probably there is some other issue with the way your controller method is implemented.

Nitinkumarwis commented 3 years ago

Let me explain you what I am trying to do is that I am having four templates (template-one, template-two, template-three, template-four) and for each template having different css/js files. Currently template-three is set to active-theme, but I am trying to dynamic, whenever i was selecting template with any of these. But here I got an issue, when I am trying to select template-one, they are unable to getting the assets for template-one, they are getting the template-three assets which is statically set. And for this issue, my template design is getting wrong.

    $template_data = PagebuilderPages::findOrFail($template_id);
    if($template_id == '1'){
        config(['pagebuilder.theme.active_theme' => 'template-one']);
        $pageBuilder = new PHPageBuilder(config('pagebuilder'));
        $pageBuilder->handlePublicRequest();
    }
    else if($template_id == '2'){
        config(['pagebuilder.theme.active_theme' => 'template-two']);
        $pageBuilder = new PHPageBuilder(config('pagebuilder'));
        $pageBuilder->handlePublicRequest();

    }
    else if($template_id == '3'){
        config(['pagebuilder.theme.active_theme' => 'template-three']);
        $pageBuilder = new PHPageBuilder(config('pagebuilder'));
        $pageBuilder->handlePublicRequest();

    }
    else if($template_id == '4'){
        config(['pagebuilder.theme.active_theme' => 'template-four']);
        $pageBuilder = new PHPageBuilder(config('pagebuilder'));
        $pageBuilder->handlePublicRequest();

    }

If the condition for the template id = 1 is running it is not getting the css/js file for template-one. It is getting the assets of the template-three which i have statically set in page builder config file. So, please help me how can i get out of this.