Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Formatting a 'GroupedBy' index value

Go to End



Community Member, 5 Posts

27 June 2013 at 12:40am

Hi all,

I'm using the GroupedBy method in the templates to group a set of data by a Y-m-d formatted date. All works fine, except that I'd like to further format the index value. For example, here's how I'm using it currently:

<% loop GroupedData.GroupedBy(Day) %>
	<% loop Children %>
	<% end_loop %>
<% end_loop %>

Where (Day) relates to the following function:

public function getDay() {
	return date('Y-m-d',strtotime($this->ActivityStartDateTime));

Obviously the title then renders as a Y-m-d date (i.e. 2013-06-26), but what I'd like to do is to manipulate the $Day index value, so for example, what I'm looking to achieve is something similar to:

<% loop GroupedData.GroupedBy(Day) %>
		<span class="calendar-icon">
			<span class="month">$Day.FormatMonth</span>
			<span class="day">$Day.FormatDay</span>
	<% loop Children %>
	<% end_loop %>
<% end_loop %>

... and use a function somewhere to format the $Day value:

public function FormatMonth() {
	return date('m',strtotime($this));
public function FormatDay() {
	return date('d',strtotime($this));

If there's a way to achieve the above then I'd be grateful for some pointers from someone.