Nette Modules – How to share single template
Notice: This thread is very old.
- simonjcarr
- Member | 28
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)
- simonjcarr
- Member | 28
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)