problem s promenou v sablonach

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
Stig
Člen | 29
+
0
-

ahoj, muze mi prosim nekdo poradit s nasledujici problemem?

mam sablonu clanky.phtml

{include pridat.phtml}

<table id="layout_table">
  <tr>
    <td id="layout_td_1">

      {include #pridat}

      <p class="topic">{$nadpis}</p>
      <div class="inner">

      {foreach $news_section as $values}
        <p><a href="#">{$values->nazev}</a></p>
      {/foreach}

      </div>
    </td>

    <td id="layout_td_2">
...

a sablonu pridat.phtml

{block #pridat}
	{$form_pridat}
{/block}

sablonu pridat.phtml zobrazuji v clanky.phtml

problem pri spusteni clanky.phtml:
promenne z pridat.phtmt se nenactou v sablone clanky.phtml (Undefined variable: form_pridat…). Samotna sabona pridat.phtml funguje.

presenter je spolecny:

<?php

require_once dirname(__FILE__) . '/BossPresenter.php';

class ClankyPresenter extends BossPresenter
{

	public function renderClanky()
	{
		$this->template->nadpis = "NOVÁ SEKCE";

		$form = $this->getComponent('novaSekceForm');
		$form['save']->caption = 'Add';
		$this->template->form_nova = $form;

		$sql = new Sql;
		$this->template->news_section = $sql->findAll('news_section')->orderBy('id');

	}

  public function renderPridat()
	{
		$form = $this->getComponent('novaSekceForm');
		$form['save']->caption = 'Add';
		$this->template->form_pridat = $form;
	}
  protected function createComponent($name)
	{
		switch ($name) {
		case 'novaSekceForm':
			$id = $this->getParam('id');
			$form = new AppForm($this, $name);
			$form->addText('nazev', 'Název')
				->addRule(Form::FILLED, 'Please enter an nazev.');

			$form->addSubmit('save', 'vytvořit')->getControlPrototype()->class('default');
			$form->onSubmit[] = array($this, 'novaSekceFormSubmitted');

			$form->addProtection('Please submit this form again (security token has expired).');
			return;

		...


		default:
			parent::createComponent($name);
		}
	}
?>

dik

Editoval Stig (28. 11. 2010 22:21)

bojovyletoun
Člen | 667
+
0
-

když se na to rychle podívám, tak nevím, kde je prom. nadpis_pridat definovná.
chtělo by to na ukázku kod, kde je definovaná.

nebo jde o problém, platnosti proměnných,

westrem
Člen | 398
+
0
-

Vsak to je ale predsa jasne .. ty vypusijes clanky.phtml a tudiz sa vykona metoda renderClanky() .. lenze ty premennu $form_pridat definujes iba v renderPridat a tato metoda sa nevola (nema preco) – vzdy sa vola render metoda iba hlavnej sablony .. nadefinuj tutu premennu aj tam a bude to ok.

westrem
Člen | 398
+
0
-

Pripadne mozes mat chybku v kode tu:

//v metode renderClanky()
$this->template->form_nova = $form; // namiesto form_pridat
Stig
Člen | 29
+
0
-

aha, diky, cekal sem ze se funkce renderPridat() spusti automaticky kdyz se zobrazuje /ikdyz ne primo/ jeji sablona.

Šaman
Člen | 2635
+
0
-

Provede se renderClanky, pohled si načte šablonu clanky.phtml a pouze na úrovni šablon (bez presenteru) si načte i soubor pridat.phtml.
Nejde o šablonu ale o pohled (view) a ten je clanky.