0
votes

Say, there is a page /catalog which is a parent to all products. I can have permanent routes with pages, e.g. /catalog/product/1, /catalog/product/2 etc.

But a user can choose any other page to be a parent page for catalog products, e.g. /stock.

How can I render products data on a variable node, e.g. /{variable-page}/product/{id}?

It's easy with multiple pages for each product - just make a block 'product_list' to render all products on a parent page and a block 'product' to render each product on a child page of the product_list.

But I don't want a million pages. I need only 1 page to render DB content of any product under a parent page where its name and route can change.

1

1 Answers

0
votes

Not sure it's the best way though... The following works. Now it doesn't matter which page has the product list, any child is taken care of at /whatever/product/uid

Controller:

public function action_product($uid = 0)
{
    $product = Product::getByUID($uid);
    if ($product instanceof Product) {
        $this->set('product', $product);
        $this->runAction('product');
    }
    else {
        $this->runAction('view');
    }
}

View:

if ($controller->getAction() === 'product') {
    ...
} else {
    ...
}