Redraw control that expects some argument in render

Member | 15

Hi there.
I understand this is not possible, although I want to understand why and if there's a plan to support this.

Let's imagine this piece of code:

{foreach $products as $product}
<h2>Product: {$product->name}</h2>
Buy: {control buyButton:small, product => $product}

If user clicks on the button, I want to check if there's any product left in the stock and based on that information I want to show how many pieces there are left. Then I'd expect to have component's handler similar to this:

public function handleAddToBasket($id)
    $product = $this->presenter->db->table('items')->get($id); // Get the product from DB
    $this->presenter->cart->addProduct($id, $product); // ++ product to cart
    $this->presenter->getComponent('basket')->redrawControl(); // Redraw the basket in page's header
    $this->redrawControl('buyButton', TRUE, $id); // Redraw THE buy button

If I simply call $this->redrawControl(‘buyButton’) I'm getting error “Missing expected parameter for render()” which I understand.

So, the question is, is it possible to implement something like this?

BTW. I've tried the snippetArea without luck. The component buyButton needs the ID and the snippetArea does not help with this.




snippetArea cannot be in included template. Have you tried to wrap included template in snippetArea?

4 years ago
Member | 124

It is usually better idea to have multiple controls than to render one control multiple times.
Take a look at Multiplier, it should help you.



Yes! This looks exactly as what I wanted. Thanks.

BTW. Is there a mention about Multiplier in docs or not? If not, would be worth it to put it there…

4 years ago