[Turbo] Add Twig Extensions for meta tags#2618
Conversation
Kocal
left a comment
There was a problem hiding this comment.
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.
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.
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! |
meta tags
|
I added 3 new |
Kocal
left a comment
There was a problem hiding this comment.
Thanks!
Can you squash/rebase your PR and fix issues found by DoctorRST please?
|
Status: Needs work |
|
I have squash and fix issues found by DoctorRST. |
|
Thanks @seb-jean. |
Hi,
I added Twig extensions for
metatags:turbo_exempts_page_from_cacheturbo_exempts_page_from_previewturbo_page_requires_reloadturbo_refreshes_withturbo_refresh_methodturbo_refresh_scroll