Ako na zmenu atribútu class v template?

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

Zdravím,

potrebujem v template zmeniť atribú class prvku.

Moja template vychádza z https://forum.nette.org/…0-radku-kodu?… ciže

<fieldset n:foreach="$form->groups as $group" n:if="$group->controls && $group->getOption('visual')" n:block="#group">
...
	<table n:block="#controls">
		<tr{attr class('required', $control->getOption('required'))} n:foreach="$group->controls as $control" n:if="!$control->getOption('rendered')" n:block="#pair">
			<th n:block="#label">{if $control instanceof Button || $control instanceof Checkbox}&nbsp;{else}{!$control->label}{/if}</th>
			<td n:block="#control">{!$control->control}{if $control instanceof Checkbox}{!$control->label}{/if}</td>
		</tr>
	</table>
...
</fieldset>

Pokúsm sa pristúpiť ku controlu elementu pomocou getControl() no v tomto momente dôjde k jeho naklonovaniu (https://api.nette.org/…rol.php.html#386) a teda zmeny sa na zobrazenom prvku vôbec neprejavia.

Príklad:

$x = $control->getControl();
$x->class('mojaTrieda');
Debug::dump($control->getControl());
Debug::dump($x);

Výstup:

object(Html) (4) {
   "name" private => string(5) "input"
   "isEmpty" private => bool(TRUE)
   "attrs" => array(8) {
      "type" => string(4) "text"
      "size" => NULL
      "maxlength" => NULL
      "class" => array(1) {
         "text" => bool(TRUE)
      }
      "name" => string(8) "username"
      "disabled" => bool(TRUE)
      "id" => string(25) "frmmyProfileForm-username"
      "value" => string(4) "demo"
   }
   "children" protected => array(0)
}


object(Html) (4) {
   "name" private => string(5) "input"
   "isEmpty" private => bool(TRUE)
   "attrs" => array(8) {
      "type" => string(4) "text"
      "size" => NULL
      "maxlength" => NULL
      "class" => string(10) "mojaTrieda"
      "name" => string(8) "username"
      "disabled" => bool(TRUE)
      "id" => string(25) "frmmyProfileForm-username"
      "value" => string(4) "demo"
   }
   "children" protected => array(0)
}

Neviete ako to spraviť tak, aby sa to fungovalo? :)
Ďakuejm!

redhead
Člen | 1313
+
0
-
$x = $control->getControlPrototype();
$x->class('mojaTrieda');
RichardT
Člen | 42
+
0
-

už to beží, díki moc!