SilverStripe 2.4.7
Hi
I’m trying to put together a template to structure my JSON. My classes have relationships as follows.
A store can have many offers and many news articles. Offers and news articles can belong to many stores.
My template looks like this
{
"StoresHolder" : [
<% control Children %>
{
"ID" : "$ID",
"Name" : "$Name",
"Address1" : "$Address1",
"Address2" : "$Address2",
"County" : "$County",
"News" : [
<% control News %>
{
"ID" : "$ID",
"Title" : "$Title",
"DatePublished" : "$DatePublished",
"ExpiryDate" : "$ExpiryDate",
"Body" : "$Body",
"URL" : "$URL",
"Photo" : "$Photo.Filename"
}<% if Middle %>,<% end_if %>
<% end_control %>
],
"Offers" : [
<% control Offers %>
{
"ID" : "$ID",
"Title" : "$Title",
"Description" : "$Description",
"Weight" : "$Weight",
"Price" : "$Price",
"Savings" : "$Savings",
"Expires" : "$Expires",
"Photo" : "$Photo.Filename"
}<% if Middle %>,<% end_if %>
<% end_control %>
]
}<% if Last %> <% else %>,<% end_if %>
<% end_control %>
]
}
I got it working to the point that it displays only one of the offers and news articles but I can’t get any further. Any advice is hugely appreciated.
This doesn’t look right – in the sense of: Have you taken a look at something like this:
Combined with the proper handling of DataObjectSets, this should be a better approach.
Unless you have very specific reasons for requiring something different – then please state them