Skip to content

Commit be071ca

Browse files
committed
Fixes and improvements
1 parent b153499 commit be071ca

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

components/console/helpers/tree.rst

+22-13
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ The above code will output the following tree:
9696
└── templates
9797
└── base.html.twig
9898
99-
Building and Rendering a Tree
100-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99+
Building a Tree Programmatically
100+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101101

102-
You can build a tree by creating a new instance of the
103-
:class:`Symfony\\Component\\Console\\Helper\\Tree` class and adding nodes to it::
102+
If you don't know the tree elements beforehand, you can build the tree programmatically
103+
by creating a new instance of the :class:`Symfony\\Component\\Console\\Helper\\Tree`
104+
class and adding nodes to it::
104105

105106
use Symfony\Component\Console\Helper\TreeHelper;
106107
use Symfony\Component\Console\Helper\TreeNode;
@@ -129,20 +130,28 @@ This example outputs:
129130
└── tests/
130131
└── Functional/
131132
133+
If you prefer, you can build the array of elements programmatically and then
134+
create and render the tree like this::
135+
136+
$tree = TreeHelper::createTree($io, null, $array);
137+
$tree->render();
138+
139+
You can also build part of the tree from an array and then add other nodes::
140+
141+
$node = TreeNode::fromValues($array)
142+
$node->addChild('templates');
143+
// ...
144+
$tree = TreeHelper::createTree($io, $node);
145+
$tree->render();
146+
132147
Customizing the Tree Style
133148
--------------------------
134149

135150
Built-in Tree Styles
136151
~~~~~~~~~~~~~~~~~~~~
137152

138153
The tree helper provides a few built-in styles that you can use to customize the
139-
output of the tree::
140-
141-
use Symfony\Component\Console\Helper\TreeStyle;
142-
// ...
143-
144-
$tree = TreeHelper::createTree($io, $node, [], TreeStyle::compact());
145-
$tree->render();
154+
output of the tree.
146155

147156
**Default**::
148157

@@ -165,7 +174,7 @@ This outputs:
165174
└── templates
166175
└── base.html.twig
167176
168-
**Box**:
177+
**Box**::
169178

170179
TreeHelper::createTree($io, $node, [], TreeStyle::box());
171180

@@ -270,7 +279,7 @@ This outputs:
270279
. templates
271280
. base.html.twig
272281
273-
**Rounded**:
282+
**Rounded**::
274283

275284
TreeHelper::createTree($io, $node, [], TreeStyle::rounded());
276285

0 commit comments

Comments
 (0)