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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Storing and Displaying a Collection of Testimonials


Go to End


35 Posts   8502 Views

Avatar
juneallison

Community Member, 110 Posts

26 July 2011 at 7:49am

ok, we're getting somewhere! :) I used that function in my Testimonial.php file and have ended up with something like this:
https://img.skitch.com/20110725-kddb1s85i74uq79dj9ku5knfw2.jpg

I removed the space after Category and changed Title to Name. BUT selecting and adding items doesn't do anything. Actually you can see items being moved to the right box, but as soon as I save, everything returns to the left. I even double checked this via the Category tab on the very left. When I click on a category no testimonials have been associated with it.

I haven't studied this yet to see where I am possibly missing something but wanted to go ahead and share my current results.

As always any suggestions are great. thanks again for your help!

Avatar
swaiba

Forum Moderator, 1899 Posts

26 July 2011 at 9:16pm

try

 $msf = new MultiSelectField("Categories",'Testimonial Categories', $map); 

instead of...

 $msf = new MultiSelectField("Testimonial Categories",'Categories', $map); 

Avatar
juneallison

Community Member, 110 Posts

28 July 2011 at 8:48am

Swaiba - I actually missed your most recent reply in my inbox. I was just checking in here to say the problem was exactly what you just suggested.(flipping Categories and Testimonial Categories). I think I'm starting to get a better hang of things.

This multi-select works perfect now. THANK YOU! This was super helpful.

Now on to figure out the functionality I want this to have on the front end. :)

Avatar
juneallison

Community Member, 110 Posts

31 July 2011 at 1:33am

Hi Swaiba - I've started to think about the front end output and wanted to get your input on what I am thinking so far.

To back up a step here are the general functionality requirements:
1. A testimonial will appear in the header of every page (except the home page)
2. Each page will actually be assigned a group or groups of testimonials to rotate through. I haven't decided if rotate is on page load or fadein/fadeout while you are on the page. Either way I will need a random testimonial loaded from a specific group or groups.
3. Any page not assigned a specific group or groups, will pull from a couple default groups.

Here are some general thoughts so far:

1. I am going to need some sort of function to get the testimonials from the database:

function getTestimonials() {

$testmonials = DataObject::get("Testimonial");

return $testmonials;

}

2. I think I have decided I should use a big if/else statement to control the page dependent output. Maybe something like this:

<% if URLSegment = my-url-segment %>

<% else_if URLSegment = myother-url-segment %>

<% else %>

<% end_if %>

I'm guessing this would be the best approach for new pages that get created that aren't assigned to a group of testimonials. Although for children pages that all pull from the same group(s) maybe I need to use something like "if in section" ...so I'm not spelling out everything single child page.

3. For outputting the testimonial content maybe something like this would go in the if statements:

<% control getTestimonials %>

<div>$Quote<br />$Signature</div>

<% end_control %>

..but I need to add in a category filter somewhere. And actually the above would just give me list, while I need to only show one at a time. Not sure if random would happen at this level or the function level. And maybe the category filter needs to happen at the function level too.

As always, any suggestions would be great. Thanks again!

Avatar
swaiba

Forum Moderator, 1899 Posts

2 August 2011 at 1:38am

sounds good...

you shoudn't need the following function if you are only showing testimonials connected to the page, if you are showing three random ones if there are none selected then you will. the reason is the "<% control getTestimonials %>" will return the dataobjects within the relationship name.

1) you'll need to add the relationship for page many_many / belongs_many_many testimonial, then you don't need the function
2/3) if you do need the random then that can be handled with a function and you can test for <% if Testimonials %> and if true use the inbuilt relationship getter, else you can call your own custom function
I'd avoid using an if tree with hardcoded urls, instead add a check box to the page "ShowTestimonials" - much more flexible.

Avatar
juneallison

Community Member, 110 Posts

2 August 2011 at 3:35am

Swaiba - Thanks for your feedback!

Just to make sure we are on the same page. So you are basically saying it would be best to create a relationship between the page and the testimonials. As we've set up, all testimonials are assigned to one or more groups(categories). So I really need to associate a page with one or more groups. So it sounds like I then need to add a tab to every page type. Maybe we'll call that tab "Testimonial Groups". When you're on this tab you will then see the multiselect box that will allow you to associate one or more groups with the page you are currently editing.

I will need a to get random testimonials. It sounds like in my page template I can then use something like <% if TestimonialGroup %> to determine if the admin has associated testimonial groups with this page. If the user hasn't done this, than I can somehow set up the "else" to pull from a default group?

And then <% control getTestimonials %> will only pull from the groups associated with the specific page?

Finally it still sounds like I still a need a function somewhere in order to randomize these testimonials?

thanks!

Avatar
swaiba

Forum Moderator, 1899 Posts

2 August 2011 at 3:42am

Basically - yes to all!

Best of luck :)

Avatar
juneallison

Community Member, 110 Posts

2 August 2011 at 3:52am

Thanks! I'm going to take a stab at the code and will likely be in touch with more questions.