大库/nette-form-blueprints

简化 Nette 表单的手动渲染。

v1.0.0 2020-05-07 19:49 UTC

This package is auto-updated.

Last update: 2024-09-04 14:24:28 UTC


README

此工具有助于手动渲染 Nette 表单。它可以使用各种模板生成 Latte 标记。

安装

composer require daku/nette-form-blueprints

使用

与 Tracy 调试面板集成

在 config.neon 中注册扩展

extensions:
	formBlueprints: Daku\Nette\FormBlueprints\FormBlueprintsExtension

从现在起,您将能够在调试面板中看到为当前呈现器附加的所有表单生成的蓝图。

Form Blueprints Tracy panel

可选配置

formBlueprints:
	indentation: '    ' # change indentation to spaces

	# add custom templates
	templates:
		- CustomTemplate

独立使用

可以在不与 Tracy 调试面板集成的条件下生成蓝图。

示例

<?php
require __DIR__ . '/vendor/autoload.php';

// create your form
$form = new Nette\Application\UI\Form;
$form->addText('foo');
$form->addSubmit('submit');

// use the generator
$generator = new Daku\Nette\FormBlueprints\BlueprintsGenerator(new Daku\Nette\FormBlueprints\LatteFormatter(new Latte\Parser));
echo $generator->generate($form, new Daku\Nette\FormBlueprints\Templates\Bootstrap4Template);

模板

以下模板可用

  • 表格(模拟 Nette 的默认表单渲染器)
  • 换行符(仅使用换行符的简单模板)
  • Bootstrap 3
  • Bootstrap 3 水平
  • Bootstrap 3 内联
  • Bootstrap 4
  • Bootstrap 4 水平
  • Bootstrap 4 内联

可以通过实现 Daku\Nette\FormBlueprints\Templates\Template 使用额外的模板。

要求

PHP >= 7.1
Nette >= 2.4