feat(view): tag override with the as prop#2042
Open
iamdadmin wants to merge 4 commits intotempestphp:3.xfrom
Open
feat(view): tag override with the as prop#2042iamdadmin wants to merge 4 commits intotempestphp:3.xfrom
iamdadmin wants to merge 4 commits intotempestphp:3.xfrom
Conversation
Benchmark ResultsComparison of Open to see the benchmark resultsNo benchmark changes above ±5%. Generated by phpbench against commit 002e35c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've pasted below the docs I provided for it, which show usage examples, but this is I think a critical feature for flexibility, as shown in Vue/React etc.
AsAttributeTag override with the
aspropThe
asattribute allows you to transform the rendered tag of one element into another. This takes place on an instance ofGenericElement, so for example this code:Would render
The power behind this is when you use an
Expressionto determine the element.Say for example, you wish to have a
<x-link>component which renders as an<a>when the$hrefattribute is provided. In your view, use the component like so:In your
<x-link>component, define:Your page will render two links, as follows
Where this can and cannot be used
You can't use the
asAttribute on things like<x-template>,<x-slot>, etc, as these do not themselves render any HTML. They are placeholders in the page. Nor will placing it on a view component itself inherently do anything. Theasattribute CAN be passed to a ViewComponent as shown in the example above, but by itself it will actually do nothing, unless you specifically provide logic to place it where you want it.