Skip to content

Commit fd71bc8

Browse files
stlgaitsgitbook-bot
authored andcommitted
GITBOOK-22: Estelle's Oct 2 changes - Fix typos & broken code blocks
1 parent 1af896e commit fd71bc8

File tree

2 files changed

+47
-42
lines changed

2 files changed

+47
-42
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: <div class="field"> {{ for...
3+
---
4+
5+
{% tabs %}
6+
{% tab title="property access via hookable_metadata" %}
7+
<pre class="language-twig" data-title="index/some_field.html.twig" data-line-numbers><code class="lang-twig">&#x3C;div class="field">
8+
{{ form_row(hookable_metadata.context.form.some_field) }}
9+
<strong> &#x3C;/div>
10+
</strong></code></pre>
11+
{% endtab %}
12+
13+
{% tab title="variable binding" %}
14+
<pre class="language-twig" data-title="index/some_field.html.twig" data-line-numbers><code class="lang-twig">&#x3C;div class="field">
15+
{% set context = hookable_metadata.context %}
16+
{{ form_row(context.form.some_field) }}
17+
<strong> &#x3C;/div>
18+
</strong></code></pre>
19+
{% endtab %}
20+
21+
{% tab title="utility function" %}
22+
<pre class="language-twig" data-title="index/some_field.html.twig" data-line-numbers><code class="lang-twig">&#x3C;div class="field">
23+
{% set context = get_hookable_context() %}
24+
{{ form_row(context.form.some_field) }}
25+
<strong> &#x3C;/div>
26+
</strong></code></pre>
27+
{% endtab %}
28+
{% endtabs %}
Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,42 @@
11
# Passing data to your hookables
22

3-
One of the most powerful aspects of hooks & hookables is an ability to pass their data down to the children. We can have two sources of the context data:
3+
One of the most powerful aspects of hooks & hookables is the ability to pass data down to children elements. We can have two sources of context data:
44

55
* Hook-level defined data
66
* Hookable-level defined data
77

8-
The context data from these two sources are merged and passed with the metadata to the hookable template or component, so we can use them.
8+
Context data from these two sources is merged and passed to the **hookable** template or component together with the metadata , so we can access them.
99

10-
<div data-full-width="false">
10+
<div data-full-width="false"><figure><img src="../.gitbook/assets/image (1).png" alt=""><figcaption></figcaption></figure></div>
1111

12-
<figure><img src="../.gitbook/assets/image (1).png" alt=""><figcaption></figcaption></figure>
12+
### Example
1313

14-
</div>
14+
| <p>Let's assume we want to render a form in our <code>index.html.twig</code> template via a <code>form</code> variable containing a <code>FormView</code> instance.</p><p>Here, we define an <strong><code>index.form</code></strong> hook, and we can pass it the form's context data thanks to the <code>with</code> keyword.</p> |
15+
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1516

16-
### Example
17+
This means that we can technically pass down multiple pieces of data to hookables that will hook into `index.form`.
1718

1819
{% code title="index.html.twig" lineNumbers="true" fullWidth="false" %}
1920
```twig
20-
{#
21-
# we assume there is a `form` variable holding a `FormView` instance passed
22-
# from the controller
23-
#}
24-
2521
<div class="container">
2622
{{ form_start(form) }}
27-
{{ form_errors(form) }}
28-
{{ form_widget(form._token) }}
23+
{{ form_errors(form }}
24+
{{ form_widget(form._token) }}
25+
26+
{% hook 'index.form' with { form } %}
2927
30-
{% raw %}
31-
{% hook 'index.form' with { form } %}
32-
{% endraw %}
33-
{{ form_end(form, {render_rest: false}) }}
28+
{{ form_end(form, {render_rest: false} }}
3429
</div>
3530
```
3631
{% endcode %}
3732

38-
So, as we see at `line 11` we define the `index.form` hook. But also, we pass the `form` with using the `with` keyword. Thanks to it, we are able to pass multiple data to hookables that will hook into the `index.form` hook.
39-
4033
{% hint style="info" %}
4134
`with { form }` is a short-hand for `with { form: form }`, so the key for our `FormView` in the context data bag will be `form.`
4235
{% endhint %}
4336

44-
Now let's create a Twig template rendering some field from our form, and let's make it a hookable.
37+
Now let's create a Twig template that renders a field from our form and let's make it a hookable. We have 3 possible options to do this :&#x20;
4538

46-
{% code title="index/some_field.html.twig" lineNumbers="true" %}
47-
```twig
48-
<div class="field">
49-
{{ form_row(hookable_metadata.context.form.some_field) }}
50-
51-
{# we can also write it like #}
52-
53-
{% raw %}
54-
{% set context = hookable_metadata.context %}
55-
56-
{{ form_row(context.form.some_field) }}
57-
58-
{# or #}
59-
60-
{% set context = get_hookable_context() %}
61-
{% endraw %}
62-
63-
{{ form_row(context.form.some_field) }}
64-
</div>
65-
```
66-
{% endcode %}
39+
{% include "../.gitbook/includes/less-than-div-class-field-greater-than-for....md" %}
6740

6841
{% hint style="info" %}
6942
You can access the context data in multiple ways, so you can pick the one you like the most. Available options are:
@@ -72,6 +45,10 @@ You can access the context data in multiple ways, so you can pick the one you li
7245
* getting the context data bag via the Twig function like `get_hookable_context().<data_key>`
7346
{% endhint %}
7447

48+
### Override behavior
49+
50+
When the same context data key is defined at both the **hook** and **hookable** levels, the **hookable-level** value takes precedence.
51+
7552
{% hint style="info" %}
76-
Sometimes you might want to override some data that are defined at the hook-level. It is possible by defining the same context data key on the hookable level. If the same context data key is defined at both hook-level and hookable-level the hookable-level one is used.
53+
You can use this to override hook-level data by redefining the key at the hookable level.
7754
{% endhint %}

0 commit comments

Comments
 (0)