Skip to content
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

Add support for Twig\Markup #4467

Merged
merged 1 commit into from
Dec 29, 2024
Merged

Add support for Twig\Markup #4467

merged 1 commit into from
Dec 29, 2024

Conversation

nlemoine
Copy link
Contributor

No description provided.

@ruudk
Copy link
Contributor

ruudk commented Nov 23, 2024

I think this should be a generic solution, not just for this specific extension.

It also feels similar to this problem I tried to solve: #4124

@nlemoine
Copy link
Contributor Author

In the meantime, that seems legit to me. @fabpot?

@faizanakram99
Copy link
Contributor

I think this should be a generic solution, not just for this specific extension.

It also feels similar to this problem I tried to solve: #4124

It already works for core extension, {{ obj }} is casted into string

@nlemoine
Copy link
Contributor Author

nlemoine commented Dec 17, 2024

For reminder, this PR is about html_classes only (part of html-extra), not Twig {{ stringableObject }} 🙂

It handles cases likes:
(edit)
See: #4467 (comment)

{{ html_classes(class_a, {
    (stringableObjectThatMightBeConvertedToAClass): true
}) }}

Which currently throws exception.

Can you please take a closer look at it? 🙏

@fabpot
Copy link
Contributor

fabpot commented Dec 18, 2024

I must be missing something here, but even without your patch, the new test passes. See #4506 where I've added your test without changing the code.

@nlemoine
Copy link
Contributor Author

nlemoine commented Dec 18, 2024

Sorry, the test case was the wrong one. You should get an error in the current code with:

{{ html_classes(stringableObjectThatMightBeConvertedToAClass) }}

The test fixtures have been updated accordingly.

extra/html-extra/HtmlExtension.php Outdated Show resolved Hide resolved
@nlemoine nlemoine changed the title Add support for Stringable Add support for Twig\Markup Dec 19, 2024
extra/html-extra/HtmlExtension.php Outdated Show resolved Hide resolved
extra/html-extra/HtmlExtension.php Outdated Show resolved Hide resolved
Co-authored-by: Fabien Potencier <fabien@potencier.org>
@fabpot
Copy link
Contributor

fabpot commented Dec 29, 2024

Thank you @nlemoine.

@fabpot fabpot merged commit 77d36ab into twigphp:3.x Dec 29, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants