HansSchouten / PHPageBuilder

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

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

Open Nitinkumarwis opened 2 years ago

Nitinkumarwis commented 2 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.

HansSchouten commented 2 years ago

In your theme layout file you can use this syntax to load a theme related file:

<link rel="stylesheet" href="<?= phpb_theme_asset('css/style.css') ?>">

Next, this method is responsible for resolving the path to the asset of the currently active theme: https://github.com/HansSchouten/PHPageBuilder/blob/master/src/Core/helpers.php#L51

This is based on the theme.folder_url and theme.active_theme settings. Can you check/debug whether this is working?

Nitinkumarwis commented 2 years ago

Screenshot from 2021-10-27 14-43-22

The issue I'm facing now is when i am changing the config parameters using this way and when i am using the functionality of view so at footer a 404 error is appearing i don't know why i am getting this please take a look at attached screenshot. According to my assumption i think the function handlePublicRequest() is setting the use_router as true and by default the user_router function is false in the pagebuilder config file so i think thats why the 404 error is appearing. config(['pagebuilder.theme.active_theme' => 'template-four']); $pageBuilder = new PHPageBuilder(config('pagebuilder')); $pageBuilder->handlePublicRequest();