-
Notifications
You must be signed in to change notification settings - Fork 252
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
Twig Bridge - no functionality to add rule #148
Comments
You should call |
That's correct. but will only work if we know the rule to be added. So something like: {{name | slugify(null, {'&': 'and'}) }} As, you can see here the php level code doesn't know the rule but will be passed from template Regards, |
This configuration would also be appreciated on SF bridge. Something like this or anything that allow us to addRule for simple cases.
|
@nei This would be the correct approach for solving this. When we are talking about just the Twig integration because it could be part of the SF bridge, but it could also mean just straight-up Twig. Alternatively for Twig we could add a |
@florianeckerstorfer adding a tag would be a better option ... I was more talking about the scenario where the Frontend guys don't know anything about the backend and have no knowledge about the configurations, in that scenario they can just pass and new rules directly from the twig template and no change in the backend will be required |
@harsain Putting this kind of logic inside your template seems like a good idea to get unmanageable code. |
As per the documentation, slugify has a method addRule which we can call to add custom rules, same is not available via twig bridge.
We have a use-case where we want to use the filter with a custom filter. So I started looking at the code base and seems it can be done with a small change to the SlugifyExtension. I have got it working on my environment and just wanted to your views before I submit a pull request.
Use-Case:
We have words like "Snacks & Bars", which we want to be converted to "snacks-and-bar". Using Slugify class it can be easily done by using the method addRule('&', 'and'), but we are using it in the twig as a filter.
So the change will be as follows:
Regards,
The text was updated successfully, but these errors were encountered: