You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/1-essentials/02-views.md
+63-4Lines changed: 63 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -215,9 +215,9 @@ Since `:isset` is a shorthand for `:if="isset()"`, it can be combined with `:els
215
215
<h1:else>Title</h1>
216
216
```
217
217
218
-
#### `:foreach` and `:{:hl-keyword:forelse:}`
218
+
#### `{:hl-property::foreach:}` and `:{:hl-property:forelse:}`
219
219
220
-
The `:foreach` directive may be used to render the associated element multiple times based on the result of its expression. Combined with `:{:hl-keyword:forelse:}`, an empty state can be displayed when the data is empty.
220
+
The `{:hl-property::foreach:}` directive may be used to render the associated element multiple times based on the result of its expression. Combined with `:{:hl-property:forelse:}`, an empty state can be displayed when the data is empty.
221
221
222
222
```html
223
223
<li:foreach="$this->reports as $report">
@@ -249,26 +249,35 @@ The example above will only render the child `div` elements:
249
249
### Tag override with the `as` prop
250
250
251
251
The `as` attribute allows you to transform the rendered tag of one element into another. This takes place on an instance of `GenericElement`, so for example this code:
252
+
252
253
```html
253
254
<aas="button">My Link</a>
254
255
```
256
+
255
257
Would render
258
+
256
259
```html
257
260
<button>My Link</button>
258
261
```
262
+
259
263
The power behind this is when you use an `Expression` to determine the element.
260
264
261
265
Say for example, you wish to have a `<x-link>` component which renders as an `<a>` when the `$href` attribute is provided. In your view, use the component like so:
266
+
262
267
```html
263
268
<x-linkhref="https://tempestphp.com">Click to go to an awesome website</x-link>
Tempest will attempt to apply `{html}class`, `{html}style`, and `{html}id` automatically, when they are passed to a view component. For example:
382
+
368
383
```html index.view.php
369
384
<x-buttonid="myBtn"style="color: red;" />
370
385
```
386
+
371
387
With the above, Tempest will attempt to apply `{html}style`, and `{html}id` automatically. As `{html}class` isn't configured, it isn't applied.
372
388
373
389
In the view component itself, you can configure `{html}class`, `{html}style`, and `{html}id` to anything you want, and Tempest will not overwrite them. You can of course, also then use these classes however you want to use them:
-`{html}id` will now default to `mybtn_(sequence generated by uniqid)`,
381
400
-`{html}style` will not appear automatically, as it was not supplied,
382
401
-`{html}class` will have a default, you can of course instead concatenate these strings, or use a CVA utility for smart class merging, or anything you want.
The `removeKeys` method returns all key=>value pairs, except for those specified. You can also use the `filter` method if you need to use a closure to filter.
The `removeKeysExcept` method returns only the specified key=>value pairs. You can also use the `filter` method if you need to use a closure to filter.
<x-buttonhref="https://tempestphp.com"label="Tempest, the framework that gets out of your way" />
461
499
```
500
+
462
501
Tempest will spread the supplied attributes, and as we also used the `AsAttribute` to convert it to a `{html}a` when `$href` is populated, you will get a hyperlink:
502
+
463
503
```html
464
504
<ahref="https://www.tempestphp.com"target="_blank">Tempest, the framework that gets out of your way</a>
465
505
```
@@ -586,10 +626,12 @@ To override this behaviour and manually control in which view component your slo
586
626
#### Extendable view component example using `define`
587
627
588
628
Let us assume you have an `x-container` view component, which is a `<div>` with formatting to act as a flex container for responsive sizing. You use this component repeatedly across your project, and it's effectively a macro to open and close the `<div>`; it doesn't have any slots or do anything special itself otherwise, with only a default `<x-slot/>` to render whatever it is given.
Now, assume we have an `x-header` in which we wish to use the `x-container`. Our `x-header` wishes to place slots `left` and `right` inside it; `x-header` owns these slots and wishes to expose these slots at the callsite in case they need custom content. Using the `define` keyword tells Tempest to treat these slots as *defined* by `x-header` instead of as a *slot to fill* inside `x-container`. Using `name` here instead of `define` would mean that Tempest falls back to the AST, and treats them as if they are slots of `<x-container>`.
634
+
593
635
```html x-header.view.php
594
636
<header>
595
637
<x-slotname="top" />
@@ -607,17 +649,21 @@ Now, assume we have an `x-header` in which we wish to use the `x-container`. Our
607
649
<x-slotname="bottom" />
608
650
</header>
609
651
```
652
+
610
653
At the callsite, you still use the `name` attribute to define which slot you're placing content into:
654
+
611
655
```html callsite.view.php
612
656
<x-header>
613
657
<x-slotname="left">Some content I want to insert</x-slot>
614
658
</x-header>
615
659
```
660
+
616
661
This example would replace the default content `<x-header-left />` instead with the literal string `Some content I want to insert` - or whatever you provide.
617
662
618
663
#### Populating a child's name slot using `define`
619
664
620
665
You can also push content into a child's named slot, not just the default slot, by creating a `define`d slot as follows:
666
+
621
667
```html x-outer.view.php
622
668
<divclass="outer">
623
669
<x-inner>
@@ -627,12 +673,15 @@ You can also push content into a child's named slot, not just the default slot,
627
673
</x-inner>
628
674
</div>
629
675
```
676
+
630
677
Again, the `define` keyword registers a `left` slot against the view component `<x-outer>` irrespective of it's position in the AST, and means that at the callsite:
678
+
631
679
```html outercallsite.view.php
632
680
<x-outer>
633
681
<x-slotname="left">My override</x-slot>
634
682
</x-outer>
635
683
```
684
+
636
685
And so, this places the literal string `My override` into `<x-innner>`'s `left` slot.
637
686
638
687
### Dynamic view components
@@ -757,7 +806,9 @@ This component provides the ability to inject any icon from the [Iconify](https:
Copy file name to clipboardExpand all lines: docs/2-features/13-static-pages.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,7 +113,7 @@ The only thing left to do is to generate the static pages:
113
113
114
114
## Crawling for dead links
115
115
116
-
Optionally, you can instruct the static generate to crawl your pages to scan for dead links. This is done by passing the `--crawl` option to the `static:generate` command:
116
+
Optionally, you can instruct the static generate to crawl your pages to scan for dead links. This is done by passing the `--crawl` option to the `{txt}static:generate` command:
117
117
118
118
```console
119
119
<dim>./tempest static:generate --crawl</dim>
@@ -127,6 +127,6 @@ By default, the crawler will only check for internal dead links. If you want to
127
127
128
128
## Production
129
129
130
-
Static pages are generated in the `/public` directory, as `index.html` files. Most web servers will automatically serve these static pages for you without any additional setup.
130
+
Static pages are generated in the `{txt}/public` directory, as `index.html` files. Most web servers will automatically serve these static pages for you without any additional setup.
131
131
132
132
Note that static pages are meant to be generated as part of your deployment script. That means the `{txt}./tempest static:generate` command should be in your deployment pipeline.
0 commit comments