Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Turbo] Add Twig Extensions for meta tags#2618

Merged
Kocal merged 1 commit into
symfony:2.xfrom
seb-jean:feat/twig-extensions
Mar 27, 2025
Merged

[Turbo] Add Twig Extensions for meta tags#2618
Kocal merged 1 commit into
symfony:2.xfrom
seb-jean:feat/twig-extensions

Conversation

@seb-jean
Copy link
Copy Markdown
Contributor

@seb-jean seb-jean commented Mar 2, 2025

Q A
Bug fix? no
New feature? yes
Docs? yes
Issues Fix #...
License MIT

Hi,

I added Twig extensions for meta tags:

  • turbo_exempts_page_from_cache
  • turbo_exempts_page_from_preview
  • turbo_page_requires_reload
  • turbo_refreshes_with
  • turbo_refresh_method
  • turbo_refresh_scroll

@carsonbot carsonbot added Turbo Status: Needs Review Needs to be reviewed labels Mar 2, 2025
@Kocal Kocal added the Feature New Feature label Mar 4, 2025
Copy link
Copy Markdown
Member

@Kocal Kocal left a 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 🙏🏻

Comment thread src/Turbo/src/Twig/TwigExtension.php
return $this->turboRefreshMethod($method).$this->turboRefreshScroll($scroll);
}

public function turboRefreshMethod(string $method = self::REFRESH_METHOD_REPLACE): string
Copy link
Copy Markdown
Member

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
Copy link
Copy Markdown
Member

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

@carsonbot carsonbot added Status: Needs Work Additional work is needed and removed Status: Needs Review Needs to be reviewed labels Mar 4, 2025
@smnandre
Copy link
Copy Markdown
Member

smnandre commented Mar 5, 2025

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).

@carsonbot carsonbot added Status: Needs Review Needs to be reviewed and removed Status: Needs Work Additional work is needed labels Mar 16, 2025
@seb-jean
Copy link
Copy Markdown
Contributor Author

Hi to you both :),

Thank you for your feedback.

I added the PHPDocs. and updated CHANGELOG.
I will add the documentation later :).

I don't think we need to have 3 methods here. What about keeping just the first two ?

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

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).

For Morphing, Turbo says the default is replace. Similarly, for Scroll preservation, Turbo indicates that the default value is reset.

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

@Kocal
Copy link
Copy Markdown
Member

Kocal commented Mar 18, 2025

Works for me then, thanks!
Maybe it could be a good idea to document (in the PHPDoc) that these new methods are "copied" from Turbo Rails?

@seb-jean
Copy link
Copy Markdown
Contributor Author

I put a few words (Inspired by Turbo Rails ...) per function. Is it better if I put those few words at the class level instead?

@Kocal
Copy link
Copy Markdown
Member

Kocal commented Mar 19, 2025

That's perfect, thanks!

@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Mar 19, 2025
@seb-jean seb-jean marked this pull request as draft March 22, 2025 15:55
@seb-jean seb-jean changed the title [Turbo] Add Twig Extensions for page refreshes [Turbo] Add Twig Extensions Mar 22, 2025
@seb-jean seb-jean marked this pull request as ready for review March 23, 2025 17:10
@carsonbot carsonbot added Status: Needs Review Needs to be reviewed and removed Status: Reviewed Has been reviewed by a maintainer labels Mar 23, 2025
@seb-jean seb-jean changed the title [Turbo] Add Twig Extensions [Turbo] Add Twig Extensions for meta tags Mar 23, 2025
@seb-jean
Copy link
Copy Markdown
Contributor Author

I added 3 new meta tags and some documentation.

@seb-jean seb-jean requested a review from Kocal March 23, 2025 17:48
Copy link
Copy Markdown
Member

@Kocal Kocal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Can you squash/rebase your PR and fix issues found by DoctorRST please?

@Kocal
Copy link
Copy Markdown
Member

Kocal commented Mar 25, 2025

Status: Needs work

@carsonbot carsonbot added Status: Needs Work Additional work is needed Status: Needs Review Needs to be reviewed and removed Status: Needs Review Needs to be reviewed Status: Needs Work Additional work is needed labels Mar 25, 2025
@seb-jean
Copy link
Copy Markdown
Contributor Author

I have squash and fix issues found by DoctorRST.

@Kocal
Copy link
Copy Markdown
Member

Kocal commented Mar 27, 2025

Thanks @seb-jean.

@Kocal Kocal merged commit 167419a into symfony:2.x Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New Feature Status: Needs Review Needs to be reviewed Turbo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants