Packages

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

Classes

  • NCacheMacro
  • NCoreMacros
  • NFormMacros
  • NMacroSet
  • NUIMacros
  • Overview
  • Package
  • 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:  * @package Nette\Latte\Macros
11:  */
12: 
13: 
14: 
15: /**
16:  * Macros for NForms.
17:  *
18:  * - {form name} ... {/form}
19:  * - {input name}
20:  * - {label name /} or {label name}... {/label}
21:  *
22:  * @author     David Grudl
23:  * @package Nette\Latte\Macros
24:  */
25: class NFormMacros extends NMacroSet
26: {
27: 
28:     public static function install(NParser $parser)
29:     {
30:         $me = new self($parser);
31:         $me->addMacro('form',
32:             '$form = $control[%node.word]; echo $form->getElementPrototype()->addAttributes(%node.array)->startTag()',
33:             '?><div><?php
34: foreach ($form->getComponents(TRUE, \'NHiddenField\') as $_tmp) echo $_tmp->getControl();
35: if (iterator_count($form->getComponents(TRUE, \'NTextInput\')) < 2) echo "<!--[if IE]><input type=IEbug disabled style=\"display:none\"><![endif]-->";
36: ?></div>
37: <?php echo $form->getElementPrototype()->endTag()');
38:         $me->addMacro('label', array($me, 'macroLabel'), '?></label><?php');
39:         $me->addMacro('input', 'echo $form[%node.word]->getControl()->addAttributes(%node.array)');
40:     }
41: 
42: 
43: 
44:     /********************* macros ****************d*g**/
45: 
46: 
47:     /**
48:      * {label ...} and optionally {/label}
49:      */
50:     public function macroLabel(NMacroNode $node, $writer)
51:     {
52:         $cmd = 'if ($_label = $form[%node.word]->getLabel()) echo $_label->addAttributes(%node.array)';
53:         if ($node->isEmpty = (substr($node->args, -1) === '/')) {
54:             $node->setArgs(substr($node->args, 0, -1));
55:             return $writer->write($cmd);
56:         } else {
57:             return $writer->write($cmd . '->startTag()');
58:         }
59:     }
60: 
61: }
62: 
Nette Framework 2.0beta1 (for PHP 5.2) API API documentation generated by ApiGen 2.3.0