ryan Posted February 15, 2019 Posted February 15, 2019 This week we take a look at what’s in ProcessWire 3.0.126 which focuses largely on resolving issue reports, but also includes a handy new $page->if() method— https://processwire.com/blog/posts/pw-3.0.126/ 15 1
Tom. Posted February 18, 2019 Posted February 18, 2019 Hi Ryan, Great update I can see me using this often - is there any plan to bring this to repeaters?
ryan Posted February 19, 2019 Author Posted February 19, 2019 Repeater pages are just another type of Page so it should work fine to use the $page->if() when $page is a repeater item. Using an $page->if('repeater_field', ...) when $page is a Page that has the repeater field on it will also work since RepeaterPageArray is a type of PageArray. Though let me know if you were thinking of something different.
Tom. Posted February 20, 2019 Posted February 20, 2019 Using foreach($page->repeater as $repeaterItem) { echo $repeaterItem->if('inventory<10', 'Low Stock', 'In Stock'); } Will come up with the error that 'if' is not a RepeaterPageArray function. 1
Autofahrn Posted February 20, 2019 Posted February 20, 2019 Sure that the error refers to RepeaterPageArray in that particular line? Should be RepeaterPage instead. And if it refers to RepeaterPage, are you sure running 3.0.126? Just tried on 3.0.126 and it works as expected. 2
adrian Posted February 20, 2019 Posted February 20, 2019 @Tom. - it seems to work fine for me also. The one thing I did notice was that if I use your exact condition, it returns 'Low Stock' even though I don't have an "inventory" field at all. Not sure if a "less than" condition should return true if the field doesn't exist or there should be an error.
Tom. Posted February 20, 2019 Posted February 20, 2019 Soo, erm, I was running 3.0.125 ? Sorry guys. 1 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now