Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • None
  • PHP

Classes

  • CacheMacro
  • CoreMacros
  • FormMacros
  • MacroSet
  • UIMacros
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (http://nette.org)
 5:  *
 6:  * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
 7:  *
 8:  * For the full copyright and license information, please view
 9:  * the file license.txt that was distributed with this source code.
10:  */
11: 
12: namespace Nette\Latte\Macros;
13: 
14: use Nette,
15:     Nette\Latte,
16:     Nette\Latte\MacroNode,
17:     Nette\Latte\ParseException,
18:     Nette\Utils\Strings;
19: 
20: 
21: 
22: /**
23:  * Macros for Nette\Forms.
24:  *
25:  * - {form name} ... {/form}
26:  * - {input name}
27:  * - {label name /} or {label name}... {/label}
28:  *
29:  * @author     David Grudl
30:  */
31: class FormMacros extends MacroSet
32: {
33: 
34:     public static function install(Latte\Parser $parser)
35:     {
36:         $me = new static($parser);
37:         $me->addMacro('form',
38:             '$form = $control[%node.word]; echo $form->getElementPrototype()->addAttributes(%node.array)->startTag()',
39:             '?><div><?php
40: foreach ($form->getComponents(TRUE, \'Nette\Forms\Controls\HiddenField\') as $_tmp) echo $_tmp->getControl();
41: if (iterator_count($form->getComponents(TRUE, \'Nette\Forms\Controls\TextInput\')) < 2) echo "<!--[if IE]><input type=IEbug disabled style=\"display:none\"><![endif]-->";
42: ?></div>
43: <?php echo $form->getElementPrototype()->endTag()');
44:         $me->addMacro('label', array($me, 'macroLabel'), '?></label><?php');
45:         $me->addMacro('input', 'echo $form[%node.word]->getControl()->addAttributes(%node.array)');
46:     }
47: 
48: 
49: 
50:     /********************* macros ****************d*g**/
51: 
52: 
53:     /**
54:      * {label ...} and optionally {/label}
55:      */
56:     public function macroLabel(MacroNode $node, $writer)
57:     {
58:         $cmd = 'if ($_label = $form[%node.word]->getLabel()) echo $_label->addAttributes(%node.array)';
59:         if ($node->isEmpty = (substr($node->args, -1) === '/')) {
60:             $node->setArgs(substr($node->args, 0, -1));
61:             return $writer->write($cmd);
62:         } else {
63:             return $writer->write($cmd . '->startTag()');
64:         }
65:     }
66: 
67: }
68: 
Nette Framework 2.0beta1 API API documentation generated by ApiGen 2.3.0