How to pass a variable from Pressenter to latte template

9 months ago

asinkan
Member | 23
+
0
-

Hello,

I have a function in the DashboardPresenter. This function calls template MyTempla

public function myFormSucceeded($button)
    {
        $this->template->name = $button->getForm()->getValues();
        $this->redirect('myTempla');

    }

how can I send my data to myTempla template?

{block content}

<h1>{$name}</h1>

I can set it in the render, but how to pass it to the render and how to call render?

public function renderMyTempla()
{
    $this->template->name=....;
}

Thx

Last edited by asinkan (2018-01-26 10:57)

9 months ago

Šaman
Member | 2253
+
+2
-

Tady se to řešilo.


Ou, sorry, this is english forum.

<?php
$this->redirect("Presenter:view", $value);

// …

public function renderView($value)
{
  $this->template->value = $value;
}
?>

Last edited by Šaman (2018-01-26 10:34)

9 months ago

David Matějka
Moderator | 5650
+
+1
-

when you redirect, variables passed to a template are lost. so either don't redirect or pass variables via url (or session)

9 months ago

asinkan
Member | 23
+
0
-

OK, the solution…

Presenter:

public function renderMyTempla($name)
    {
        $this->template->name=$name;
    }

public function myFormSucceeded($button)
    {
        $name = $button->getForm()->getValues();
        $this->redirect('myTempla',$name);
    }

Latte template:

{block content}

<h1>{$name}</h1>