Nette Modules – How to share single template

Notice: This thread is very old.
simonjcarr
Member | 28
+
0
-

At the moment I am only able to get my module template to see @layout.latte if I put it in the same module, but I want all modules to share the same layout.

How do I do that?

Last edited by simonjcarr (2016-08-10 10:02)

CZechBoY
Member | 3608
+
0
-

Do you use Nette\Application?

simonjcarr
Member | 28
+
0
-

Here is the code in my Presenter, which is located in

app
-Modules
--Post
---PostPresenter.php

My template is in

app
-Modules
--Post
---templates
----Post
-----default.latte
<?php

namespace App\Presenters;

use Nette;
use Nette\Application\UI;
use Nette\Application\UI\Form;

class PostPresenter extends Nette\Application\UI\Presenter {

    /** @var Nette\Database\Context */
    private $database;

    public function __construct(Nette\Database\Context $database) {
        $this->database = $database;
    }

    public function renderDefault() {
        $this->template->page_title = "Test Page Title";
    }

    protected function createComponentPostForm() {
        $form = new Form;
        $form->addText('title', 'Title:')
                ->setRequired()
                ->addRule(Form::MIN_LENGTH, "Title should be longer than %d characters", 3)
                ->setAttribute('class','form-control')
                ->addFilter(function($value){
                    return strtoupper($value);
                });
        $form->addTextArea('body', 'Body:')
                ->setRequired("The body of the post is required")
                ->setAttribute('class','form-control');
        $form->addHidden('author_id')->setValue(2);
        $form->addSubmit('submit', 'Save Post');
        $form->onSuccess[] = [$this, 'postFormSucceeded'];


        return $form;
    }

    public function postFormSucceeded(Form $form, $values){
        $this->flashMessage("Your post has been created",'alert-info');
    }

}

Last edited by simonjcarr (2016-08-10 11:57)

blaztar
Member | 93
+
0
-

I think you can rewrite formatLayoutTemplateFiles method in BasePresenter and extend all your other presenter from that.

Also in your template on top you can use macro layout.

{layout "./path/@layout.latte"}

Last edited by blaztar (2016-08-10 12:51)

simonjcarr
Member | 28
+
0
-

Thank you, I got it working.