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 is_numeric() function to check if variable is numeric #1861

Closed
bertoost opened this issue Oct 1, 2015 · 5 comments
Closed

Add is_numeric() function to check if variable is numeric #1861

bertoost opened this issue Oct 1, 2015 · 5 comments

Comments

@bertoost
Copy link

bertoost commented Oct 1, 2015

Title says enough I guess ;-)
Currently using this simple registered function

new \Twig_SimpleFunction('is_numeric', function ($str) {
    return is_numeric($str);
})
@bertoost bertoost changed the title Add is_numeric function to check if variable is numeric Add is_numeric() function to check if variable is numeric Oct 1, 2015
@stof
Copy link
Member

stof commented Oct 1, 2015

this should not be a function. It should be a test if you want to add it (making it look like foobar is numeric.

However, what is the use case for having it. I'm not sure it belongs to the core

@bertoost
Copy link
Author

bertoost commented Oct 1, 2015

A test would be great indeed. Didn't thought about that.

A use case...
I am getting data through some API's and sometimes a specific value is a numeric ID instead of a text string. But when numeric, I don't want to show it, or show something as "Unknown".

@SpacePossum
Copy link
Contributor

( @bertoost you can check here (for a sample implementation) https://github.com/GeckoPackages/Twig , disclaimer I wrote it)

@fabpot
Copy link
Contributor

fabpot commented Jan 11, 2016

Closing as it won't be added in Twig core, Adding it in an extension is easy enough though.

@alexislefebvre
Copy link

You can find an implementation here: https://stackoverflow.com/a/52946699/2257664

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants