Dynamic Singlepages with Area
Permalink
Hello,
i have a little Problem with a current project and need some advice.
i have a singlepage called „Details“. The controller of the singlepage loads product which id/slug is given by the first get param.
The view renders the found product item.
Now i want to add an area into the view, so that i can add/edit blocks by concrete5.
I have tried to add this Code to the page view:
And here is the problem.
If i click on „Edit page“ the get parameter which contains the url slug will be removed. So there is no more association which product should be edited.
Is it possible to pass custom get params when i click on „edit page“ ?
i have a little Problem with a current project and need some advice.
i have a singlepage called „Details“. The controller of the singlepage loads product which id/slug is given by the first get param.
public function view($slug = null) { $seo = \Core::make("helper/seo"); $productId = ProductManager::getInstance()->getProductIdBySlug($slug); if ($productId !== false) { $productEntity = ProductManager::getInstance()->getProductEntity($productId); $seo->addTitleSegment($productEntity->getName()); $this->set("product", $productEntity); } else { $this->redirect("page_not_found"); } }
The view renders the found product item.
Now i want to add an area into the view, so that i can add/edit blocks by concrete5.
I have tried to add this Code to the page view:
<?php $c = new Area('Main'); $c->enableGridContainer(); $c->display(); ?>
And here is the problem.
If i click on „Edit page“ the get parameter which contains the url slug will be removed. So there is no more association which product should be edited.
Is it possible to pass custom get params when i click on „edit page“ ?
Are you trying to add different blocks to the page based on which slug was passed into the controller? If so I do not believe this is possible. Also, you shouldn't use $c for your area, because that is the global page variable.
Hi hutman, thanks for your reply. Yes thats exactly what i am trying to do...
I'm sorry to tell you I don't think that this is going to be possible. The areas are specific to the page, not the url.
Maybe another member of the community would have another idea of how to do this, but it's not going to be as easy as adding an area to a normal page.
Maybe another member of the community would have another idea of how to do this, but it's not going to be as easy as adding an area to a normal page.
okay thank you well.
My first idea was (if it is possible to pass the slug param) to add the block container like this:
My first idea was (if it is possible to pass the slug param) to add the block container like this:
$c = new Area('Main_'. $slug);
That would probably work, what you could do is to put the slug into the session when the page loads and then if $slug is blank (edit mode) pull it from the session instead.
Thats a good idea. that should be work :)
Using a Session was a good advice. Here is my POC. It is working fine. Only bug: If you exit the edit mode the action + params can't be restored...
Code for Controller:
In the View you have to use the wrapper method $this->controller->getArea(...) instead of using new Area(...)
Example Code for the View:
Code for Controller:
<?php /** * @author Fabian Bitter * @copyright (C) 2016 Bitter Webentwicklung */ use \Concrete\Core\Page\Controller\PageController; use \Symfony\Component\HttpFoundation\Session\Session as SymfonySession; use Request; use Area; class MyPageController extends PageController { /** * Returns an inique id based on the the action + params of the page. * * @return String */
Viewing 15 lines of 53 lines. View entire code block.
In the View you have to use the wrapper method $this->controller->getArea(...) instead of using new Area(...)
Example Code for the View:
<?php $a = $this->controller->getArea("My Test Area"); $a->enableGridContainer(); $a->display(); ?>