Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use variables (shortcode) in blocks to get some data dynamically #108

Closed
saifullahakhtar opened this issue Aug 31, 2021 · 8 comments
Closed

Comments

@saifullahakhtar
Copy link

Hi, Thanks for the awesome library, I'm facing an issue, I'm trying to add a PHP variable in blocks that are defined in the controller to get some data dynamically on the page view, but unfortunately, variables aren't working. is there any other way to get the data dynamically same like Elementor page builder shortcode feature?

Thanks.

@saifullahakhtar
Copy link
Author

saifullahakhtar commented Aug 31, 2021

Let me give you a brief info on what I'm trying to achieve. For example, I have a Products table in the database and I want to create its block, If I will fetch the products list in Products Block so I will daily have to update the page as well to get the latest products because if I add the Product block in page today so the block will add the today's current products list in page and will convert it to HTML, The page will not dynamically get the updated products list tomorrow. I hope you understand what I'm trying to achieve. So please tell me if it is possible to get the latest Products daily, direct on the page which is built by Laravel page builder. I think we can achieve it via the shortcode method in block using blade file or PHP file.

@HansSchouten
Copy link
Owner

Hi yes this should be possible. If you create a block with a view.php file you can run any PHP you want inside the block (so also show details from database).

@saifullahakhtar
Copy link
Author

Hi, thanks for responding, I've tried it but my page view isn't working, I've set up a page builder in custom routes using the method in your pinned issue (Pagebuilder in a specific controller), but my view page isn't working, could you please help me to set up the custom routes for page views in multi-languages?

@saifullahakhtar
Copy link
Author

Can I get the page view in the specific controller as well? I mean how can I fetch the page data in the specific controller to view the page?

@HansSchouten
Copy link
Owner

Hi please have a look here.
This snippet renders the view in a Laravel controller:

/**
 * Edit the given page with the page builder.
 *
 * @param int|null $pageId
 * @throws Throwable
 */
public function build($pageId = null)
{
    $route = $_GET['route'] ?? null;
    $action = $_GET['action'] ?? null;
    $pageId = is_numeric($pageId) ? $pageId : ($_GET['page'] ?? null);
    $pageRepository = new \PHPageBuilder\Repositories\PageRepository;
    $page = $pageRepository->findWithId($pageId);

    $phpPageBuilder = app()->make('phpPageBuilder');
    $pageBuilder = $phpPageBuilder->getPageBuilder();

    $customScripts = view("pagebuilder.scripts")->render();
    $pageBuilder->customScripts('head', $customScripts);

    $pageBuilder->handleRequest($route, $action, $page);
}

@saifullahakhtar
Copy link
Author

Hi, I'm already using this code to build the page, but how can I make a custom Controller to view the saved page?

@saifullahakhtar
Copy link
Author

I mean how can I view the page which is built in page-builder? when I click on view in page-builder after saving the page it comes empty without any data. How can I retrieve the page data in a specific controller?

@saifullahakhtar
Copy link
Author

saifullahakhtar commented Sep 2, 2021

Issue Resolved...
Reference: Issue No.#22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants