-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
[Turbo] Add Twig Extensions #2618
base: 2.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, can you also add some tests and update the CHANGELOG (for 2.24)?
Thanks!
PS: please for the next time, keep the PR template 🙏🏻
return $this->turboRefreshMethod($method).$this->turboRefreshScroll($scroll); | ||
} | ||
|
||
public function turboRefreshMethod(string $method = self::REFRESH_METHOD_REPLACE): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some PHPDoc and a link to the documentation
return \sprintf('<meta name="turbo-refresh-method" content="%s">', $method); | ||
} | ||
|
||
public function turboRefreshScroll(string $scroll = self::REFRESH_SCROLL_RESET): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some PHPDoc and a link to the documentation
I don't think we need to have 3 methods here. What about keeping just the first two ? Also i would not set the default values in the methods and force users to be explicit (they do not need this function to set default value... and the day Turbo changes its default value it would be a real mess). |
Hi to you both :), Thank you for your feedback. I added the PHPDocs. and updated CHANGELOG.
These tags are generally used together. Turbo Rails and Turbo Laravel also use this third function. # https://github.com/hotwired/turbo-rails/blob/main/app/helpers/turbo/drive_helper.rb
# turbo_refreshes_with(method: :morph, scroll: :preserve)
def turbo_refreshes_with(method: :replace, scroll: :reset)
provide :head, turbo_refresh_method_tag(method)
provide :head, turbo_refresh_scroll_tag(scroll)
end
For Morphing, Turbo says the default is These default values are also found in Turbo Rails:
# https://github.com/hotwired/turbo-rails/blob/main/app/helpers/turbo/drive_helper.rb
# Configure method to perform page refreshes. See +turbo_refreshes_with+.
def turbo_refresh_method_tag(method = :replace)
raise ArgumentError, "Invalid refresh option '#{method}'" unless method.in?(%i[ replace morph ])
tag.meta(name: "turbo-refresh-method", content: method)
end
# Configure scroll strategy for page refreshes. See +turbo_refreshes_with+.
def turbo_refresh_scroll_tag(scroll = :reset)
raise ArgumentError, "Invalid scroll option '#{scroll}'" unless scroll.in?(%i[ reset preserve ])
tag.meta(name: "turbo-refresh-scroll", content: scroll)
end |
Works for me then, thanks! |
I put a few words ( |
That's perfect, thanks! |
Hi,
I added Twig extension:
turbo_refresh_method
Configure method to perform page refreshes
For more information: https://turbo.hotwired.dev/handbook/page_refreshes#morphing
Usage
To use this Twig extension you must write:
The possible values are
morph
orreplace
(the default).turbo_refresh_scroll
Configure scroll strategy for page refreshes.
For more information: https://turbo.hotwired.dev/handbook/page_refreshes#scroll-preservation
Usage
To use this Twig extension you must write:
The possible values are
preserve
orreset
(the default).turbo_refreshes_with
A combination of the 2 previous Twig extensions.
Usage
To use this Twig extension you must write: