Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Storing and Displaying a Collection of Testimonials

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

Page: 1 2 3 4 5
Go to End
Author Topic: 4920 Views
  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    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!

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    try

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

    instead of...

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

  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    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.

  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    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!

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    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.

  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    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!

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

    Basically - yes to all!

    Best of luck

  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Storing and Displaying a Collection of Testimonials Link to this post

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

    4920 Views
Page: 1 2 3 4 5
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.