-
Notifications
You must be signed in to change notification settings - Fork 121
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
@pushonce doesn't seem to work as Laravel's blade. #192
Comments
I'm experiencing the same issue, this is normally a very useful feature so it'd be very nice to see this brought inline with the way Laravel works! |
Changing the public function compilePushOnce($expression): string
{
$key = '';
if ($this->currentView) {
$key = '_' . $this->currentView;
}
$key = '__pushonce__' . \trim(\substr($expression, 2, -2)) . $key;
return $this->phpTag . "if(!isset(\$GLOBALS['$key'])): \$GLOBALS['$key']=1; \$this->startPush$expression; ?>";
} If @jorgecc @jorgecc-business-account could change this I would really appreciate it! I'd make a pull request but that's a little much work with how small of a change this is. |
I added another change to the code. Now it is possible to display a stack() before it is called(), i.e. Now this code is valid:
and this code is also valid
Example: |
Is the issue described now fixed as well? I don't see any changes in the code regarding |
When using @pushonce for some styles in a component, it seems that it is duplicating the styles. Looking at the docs and code it seems that the @pushonce will only work if used in the same file multiple times. However Laravel's blade uses it per component used as specified in their docs:
The @once directive allows you to define a portion of the template that will only be evaluated once per rendering cycle. This may be useful for pushing a given piece of JavaScript into the page's header using stacks. For example, if you are rendering a given component within a loop, you may wish to only push the JavaScript to the header the first time the component is rendered.
Here is copy of my component:
The text was updated successfully, but these errors were encountered: