HansSchouten / PHPagebuilder-boilerplate

Boilerplate for quickly spinning up websites using PHPagebuilder.
https://www.phpagebuilder.com
39 stars 25 forks source link

please add a more complex example block #4

Closed skerbis closed 4 years ago

skerbis commented 4 years ago

@HansSchouten could you please add a more complex example with settings perhaps? i.e how to define the input for images or sections for a slideshow? That would help aus very much to understand what to do and what's possible. Thanks for this nice solution. I'm planning to make it a REDAXO cms Addon.

HansSchouten commented 4 years ago

Hi, there is not yet support to upload images from the block settings in the pagebuilder sidebar. I will add that soon. It would be cool if the project is used in other CMSes/projects! However, although I try to make sure there are no breaking changes between versions, note that there is not yet a stable release of the PHPageBuilder project. I am still thinking about how to make migrations between versions as easy as possible.

skerbis commented 4 years ago

Thanks I'm just testing. When I start to make the AddOn I will try to help you.
Where can I see what settings for a block are possible?

HansSchouten commented 4 years ago

I just found out that the image type is actually already working. These are example settings of the currently supported setting types that can be added to a config.php of one of your blocks:

<?php
return [
    "settings" => [
        "background-image" => [
            "type" => "image",
            "label" => "Background Image",
            "value" => ""
        ],
        "title" => [
            "type" => "text",
            "label" => "Title",
            "value" => "This is the default title"
        ],
        "percentage" => [
            "type" => "number",
            "label" => "Percentage",
            "value" => "25"
        ],
        "show-paragraph" => [
            "type" => "yes_no",
            "label" => "Should we show the paragraph?",
            "value" => "0"
        ],
        "example-selector" => [
            "type" => "select",
            "label" => "Select one of the following",
            "options" => ["option1", "option2", "option3"]
        ],
    ]
];

For each setting you first define a unique key (used to store and access the setting value). Then you define the type (how it is presented in the sidebar), the label (text to show in the sidebar) and the value (which is the default value that is used if no value is set).

Next, the setting value can be accessed in a .php block via: $block->setting([setting key here]). So to show an uploaded image, use this example:

<img src="<?= e($block->setting('background-image')) ?>">
dfrey382 commented 4 years ago

how do i add blocks inside a block or container

dfrey382 commented 4 years ago

kindly list all the setting types we have, i would also like to add wysiwyg text addon

HansSchouten commented 4 years ago

This are all the setting types at the moment. Wysiwyg text editor would indeed by a nice type. However, for now I would suggest changing your block view (to a .html file or include a html block into the dynamic block using [block slug="another-block"]), so that the CKEditor can be used. Using the CKEditor directly inside the page is also easier to use than a small editor in the sidebar.

kousar2334 commented 4 years ago

``"example-selector" => [ "type" => "select", "label" => "Select one of the following", "options" => ["option1", "option2", "option3"] ], how to set default value of option and there is any way to make dynamic options value, like ["option1", "option2", "option3"] are coming from database .

HansSchouten commented 4 years ago

You can add use "value" => "option1" to set a default value.

Good suggestion to allow options from the database. I have not tried that before, but since the config.php file is a PHP file, you can add any PHP logic at the beginning of the file that requests your options from the database.

kousar2334 commented 4 years ago
``<?php
use App\Http\Controllers\backend\PageController;
$ctrl=new PageController();
$categories=$ctrl->getCategories();
return [
    'title' => 'Banner',
    'category' => 'Banner',
    'icon' => 'fa fa-server',
    "settings" => [
      "first-section" => [
            "type" => "select",
            "label" => "Select First Block Category",
            "options" =>$categories,
        ], 
  ],
];

I have written the code into config.php file. The output is Screenshot_2020-06-29_23-11-35 Screenshot_2020-06-29_23-11-59 code in controller public function getCategories() { $cats=DB::table('news_categories')->select('name')->get(); return $cats; } The select option value is undefined. How can I solve the problem?

HansSchouten commented 4 years ago

Let's discuss this here: https://github.com/HansSchouten/Laravel-Pagebuilder/issues/27