-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[12.x] Add @context
Blade directive
#56146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[12.x] Add @context
Blade directive
#56146
Conversation
@context
Blade directive
This is good and useful. The only problem that I see with it is the fact that the context has two data: normal and hidden, so it might be better to add an argument |
@devajmeireles It just delegates to the framework/src/Illuminate/Foundation/helpers.php Lines 332 to 350 in 6262237
|
I see, maybe we can adapt the helper before your PR to enable interaction with hidden values. |
@martinbean I just noticed we can interact with the hidden data even if we do not have the context()->has('foo');
context()->hasHidden('bar'); |
@martinbean Thanks for the implementation A word of warning: I just found out that it was a breaking change for our website and I think it might be for many more. This is easily fixed by adding a "@" making it "@@context". |
@WouterDeGeringel thanks for the heads-up; just got hit by that. |
@WouterDeGeringel Sorry to hear that. I’m not sure what you’d like me to do, though? The release notes do also mention the inclusion of this new directive, so did you just update the framework version without checking what was included in the update? I imagine adding any Blade directive is going to be a breaking change for someone somewhere if they’re including code that includes an That being said, there are ways to deal with this, such as using the @verbatim
<script type="application/ld+json">
{
"@context": "https://schema.org",
// ...
}
</script>
@endvertbatim But personally, when I’ve dealt with JSON-LD data before, I’ve generated the JSON using PHP and then printed it in my Blade templates using the <script type="application/ld+json">@json($schema)</script> This then eliminates the possibility of content containing |
I caught it locally when running Dusk tests, so no servers were harmed =) This last release was 2 weeks in the oven, and I was eager for another PR to land.
That is what I ended up using.
For dynamic JSON-LD, such as metadata for videos, I do that. But for static ones, such as organization data that never changes, I usually have it directly on the blade file. Nonetheless, the |
@martinbean Thanks for the examples...the @verbatim directive is a better solution then mine, I think.
Thanks again for you work. |
@taylorotwell this should not have been in a minor release since it breaks your app if you use https://schema.org/ structure 😑 |
This also breaks our site because of the JSON-LD: <script type="application/ld+json">
{
"@context": "https://schema.org",
// ...
}
</script> But I think we may consider wrapping everything that uses |
Adds a new
@context
Blade directive, that operates similar to the existing@session
directive.Context Directives
The @context directive may be used to determine if a context value exists. If the context value exists, the template contents within the
@context
and@endcontext
directives will be evaluated. Within the@context
directive’s contents, you may echo the$value
variable to display the context value:This makes it easy to check if a context value is set and if so, to obtain its value, in Blade templates. My particular use case: