Walter471 Posted November 10, 2019 Share Posted November 10, 2019 Hi. I'm have used $page->if several times and find it quite useful. Today I tried to output some string depend on date field, like setViewData([ 'news' => $news->explode(function ($news_item) { return WireData([ 'title' => $news_item->title, 'date' => $news_item->if('publish_from=today', 'yes', 'no'), 'link' => $news_item->url ]); }) ]); It returns 'no' for all items, but it should return yes for some of them. I have tested it with 'created' field and it also doesn't work pages('id>1000')->each(function ($item) { d(date("Y-m-d", strtotime('today'))); d(date("Y-m-d", $item->created), $item->if('created=today', 'yes', 'no')); }); Should I consider it as a bug and open an issue or I miss something and didn't understand the description of $key argument for $page->if() ? Regards. Link to comment Share on other sites More sharing options...
Zeka Posted November 10, 2019 Share Posted November 10, 2019 setViewData([ 'news' => $news->explode(function ($news_item) { return WireData([ 'title' => $news_item->title, 'date' => $news_item->if('publish_from=today', 'yes', 'no'), 'link' => $news_item->url ]); }) ]); This part looks very familiar to me)))) Try something like pages('id>1000')->each(function ($item) { $today = strtotime('today'); d(date("Y-m-d", $item->modified), $item->if("modified>=$today, modified<tomorrow", 'yes', 'no')); }); 1 Link to comment Share on other sites More sharing options...
Walter471 Posted November 11, 2019 Author Share Posted November 11, 2019 Thanks for the solution.. Regards, Walter Link to comment Share on other sites More sharing options...
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