a-ok Posted September 25, 2017 Share Posted September 25, 2017 Is it possible to format a date in when using a date field as the 'Repeater item label'? Quote Enter the field name to use for repeater labels in the page editor, or leave blank to auto-generate. To use multiple fields, or to specify your own format string, surround field names in {brackets}. To include a repeater index number with each label, add "#n" somewhere in your format string. {events_detail_dates_start_date} obviously returns the timestamp but we can't input PHP here in so I'm guessing not... but any thoughts? Link to comment Share on other sites More sharing options...
abdus Posted September 25, 2017 Share Posted September 25, 2017 You can hook into InputfieldRepeater::renderRepeaterLabel and change $event->return. wire()->addHookAfter('InputfieldRepeater::renderRepeaterLabel', function (HookEvent $e) { $field = $e->object->hasField; // check the field if ($field != "myRepeaterField") return; /** @var Page $page */ $count = $e->arguments('cnt'); $page = $e->arguments('page'); $labelDate = date('y-m-d', $page->published); $label = substr($page->getText('title|body'), 0, 20); $e->return = "{$label} -- {$labelDate}"; }); Which renders as From the core: // InputfieldRepeater.module /** * Render the repeater label * * @param string $label Default label * @param int $cnt Item index (1-based) * @param Page $page Repeater item * @return string * */ public function ___renderRepeaterLabel($label, $cnt, Page $page) { ... } 2 Link to comment Share on other sites More sharing options...
a-ok Posted September 25, 2017 Author Share Posted September 25, 2017 15 minutes ago, abdus said: You can hook into InputfieldRepeater::renderRepeaterLabel and change $event->return. /** * Render the repeater label * * @param string $label Default label * @param int $cnt Item index (1-based) * @param Page $page Repeater item * @return string * */ public function ___renderRepeaterLabel($label, $cnt, Page $page) {... } Thanks for the help. I did try this but it's returned as 1 January 1970. 'events_detail_dates' is the repeater and 'events_detail_dates_start_date' is the date field. $wire->addHookAfter('InputfieldRepeater::renderRepeaterLabel', function($event) { if ($event->object->hasField == 'events_detail_dates') { $event->return = date('D. j F Y', $event->events_detail_dates_start_date); } }); Link to comment Share on other sites More sharing options...
abdus Posted September 25, 2017 Share Posted September 25, 2017 You need to use $page argument. Also remember to check if field is actually the field you want. wire()->addHookAfter('InputfieldRepeater::renderRepeaterLabel', function (HookEvent $e) { /** @var Page $page */ $field = $e->object->hasField; // check the field if ($field != "events_detail_dates") return; $page = $e->arguments('page'); $e->return = date('D. j F Y', $page->events_detail_dates_start_date); }); 3 Link to comment Share on other sites More sharing options...
a-ok Posted September 25, 2017 Author Share Posted September 25, 2017 1 hour ago, abdus said: You need to use $page argument. Also remember to if the field is actually the field you want wire()->addHookAfter('InputfieldRepeater::renderRepeaterLabel', function (HookEvent $e) { /** @var Page $page */ $field = $e->object->hasField; // check the field if ($field != "myEventsRepeater") return; $page = $e->arguments('page'); $e->return = date('D. j F Y', $page->events_detail_dates_start_date); }); Thanks, abdus! 1 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