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: examples/src/md/introduction.md
+87-1
Original file line number
Diff line number
Diff line change
@@ -601,6 +601,74 @@ You can also notice how the `class` attribute is merged with `class` attribute o
601
601
You can change how attributes are merged by passing via options a callback function used by lodash method [mergeWith](https://lodash.com/docs/4.17.15#mergeWith).
602
602
By default, it's used to concat array.
603
603
604
+
By default, all props are scoped to the component, and are not available to nested components. You can however change this accordingly to your need.
605
+
Let's see below example.
606
+
607
+
Create a component:
608
+
609
+
```html
610
+
<!-- src/child.html -->
611
+
<scriptprops>
612
+
module.exports= {
613
+
prop:'Default prop value'
614
+
}
615
+
</script>
616
+
<div>
617
+
Prop in child: {{ prop }}
618
+
</div>
619
+
```
620
+
621
+
Create another component that use the first one:
622
+
623
+
624
+
```html
625
+
<!-- src/parent.html -->
626
+
<scriptprops>
627
+
module.exports= {
628
+
prop:'Default prop value'
629
+
}
630
+
</script>
631
+
<div>
632
+
Prop in parent: {{ prop }}
633
+
<x-child></x-child>
634
+
</div>
635
+
```
636
+
637
+
Use:
638
+
639
+
```html
640
+
<x-parentprop="My prop"></x-parent>
641
+
```
642
+
643
+
The output will be:
644
+
645
+
```html
646
+
<div>
647
+
Prop in parent: My prop
648
+
<div>
649
+
Prop in child: Default prop value
650
+
</div>
651
+
</div>
652
+
```
653
+
654
+
As you can see `prop` in `x-child` component are default value and not the one set via `x-parent`. Prepend `aware:` to the attribute name to pass the props to nested components.
655
+
656
+
657
+
```html
658
+
<x-parentaware:prop="My prop"></x-parent>
659
+
```
660
+
661
+
The output now will be:
662
+
663
+
```html
664
+
<div>
665
+
Prop in parent: My prop
666
+
<div>
667
+
Prop in child: My prop
668
+
</div>
669
+
</div>
670
+
```
671
+
604
672
### Attributes
605
673
606
674
Your can pass any attributes to your components and this will be added to the first node of your component, or to the node with an attribute named `attributes`.
@@ -908,4 +976,22 @@ NOTE: If you change `<yield>` tag to `<content>` to support your existing code,
908
976
909
977
### PostHTML Extends
910
978
911
-
Not yet tested.
979
+
So far it works fine together with `posthtml-components` plugin.
980
+
981
+
## Contributing
982
+
983
+
See [PostHTML Guidelines](https://github.com/posthtml/posthtml/tree/master/docs) and [contribution guide](CONTRIBUTING.md).
Thanks to all PostHTML contributors and especially to `posthtml-extend` and `posthtml-modules` contributors, as part of code are ~~stolen~~ inspired from these plugins.
997
+
Huge thanks also to Laravel Blade template engine.
0 commit comments