Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » [SOLVED] Drill down on frontpage

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3
Go to End
Author Topic: 2439 Views
  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: [SOLVED] Drill down on frontpage Link to this post

    If I understand the functionality you want, I would render all the content on the page and then hide and show elements of it using jQuery but I'm more comfortable with JavaScript than PHP.

    Something like this: http://roshanbh.com.np/examples/exapandable-panel/

    Here is the Source
    http://roshanbh.com.np/2008/03/expandable-collapsible-toggle-pane-jquery.html

    There are more fancy versions of this but this was the first one a quick Google search revealed

  • UncleCheese
    Avatar
    4085 Posts

    Re: [SOLVED] Drill down on frontpage Link to this post

    Ohh.. I see now. Thank you for clearing that up, zenmonkey.

    Here's a jQuery script I use for all my blind-down toggles.

    toggle.js

    $(function() {
    $('.toggle-content').hide();
          $("a[@rel=toggle]").click(
             function() {
                $(this).toggleClass("open");
                $("#toggle-content-" + this.id.replace('toggle-','')).slideToggle("fast");
                return false;
             }
          );
       }
    );

    Usage:

    <a rel="toggle" id="toggle-$ID">Show details</a>
    <div id="toggle-content-$ID" class="toggle-content">Some more content here...</div>

    Where $ID is a unique number that will be the same on a block of content and its corresponding link.

  • dubtje
    Avatar
    Community Member
    17 Posts

    Re: [SOLVED] Drill down on frontpage Link to this post

    Maybe the jquery-trick can help, I'll give it a try,

    But trying to be a bit more clear. I'm converting a custom-made site (cake-php) to silverstripe, so I can show the current site:
    http://www.savedbythebell.be/kaart/provincie/West-Vlaanderen

    This is exactly what I want to reach: a list of schools, and when clicking the name, getting the details,

    thanks for your patience

  • banal
    Avatar
    Community Member
    901 Posts

    Re: [SOLVED] Drill down on frontpage Link to this post

    I don't think you'll need jQuery for this. SilverStripe should handle this just fine:
    A) place the following code in your ActionPage_Controller class

    protected $detailData;

    public function details(){
       // get the id parameter
       $id = intval(Director::urlParam('ID'));

       // get the DataObject with the given ID and store it in $detailData
       $this->detailData = DataObject::get_by_id('Action', $id);

       // return empty array, so that the correct templates are being used
       return array();
    }

    // accessor for the detail data
    public function DetailData(){
       return $this->detailData;
    }

    B) after that, you should be able to call the "details" method, by appending details/id to your page-url, where id is your DataObject ID. Example: http://yoursite.com/your-action-page/details/5
    The method will fetch the DataObject with the given ID and assign it to the detailData member-variable. This can then be accessed in the Template using $DetailData.

    C) The beauty of this is, that you can use a custom Template (or Layout) file for the details page. Just name it: ActionPage_details.ss. In this template you can then call something like:

    <% control DetailData %>
    ... access all memebers of the Action DataObject here ...
    <% end_control %>

    There are actually several possible solutions to this problem, this is just one of them (that works for me). I think it's also possible to directly return data to the template renderer by returning some special formatted array (instead of an emtpy one). But the proposed method works equally well.

  • UncleCheese
    Avatar
    4085 Posts

    Re: [SOLVED] Drill down on frontpage Link to this post

    That's the thing, though. There is no DataObject. The school name is just free text. If it were a has_one relation to school, you could use the /details/$ID approach, but I'm not sure that's what he's looking for.

  • dubtje
    Avatar
    Community Member
    17 Posts

    Re: [SOLVED] Drill down on frontpage Link to this post

    @banal tnx a lot! This is what I was looking for and worked like a charm.
    @UncleCheese maybe it was unclear, but there is a DataObject (Actions), $organisatie was just one argument of it. Tnx for thinking with me.

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: [SOLVED] Drill down on frontpage Link to this post

    Hi!

    Now that's off-topic, but I tried the toggle.js JavaScript exactly as described by UncleCheese in one of my pages, adding this to Controller:

    function init() {
       parent::init();
       Requirements::javascript('jsparty/jquery/jquery.js');
       Requirements::javascript('mysite/javascript/toggle.js');
    }

    Both files are being loaded, but Firebug says: $(".toggle-content") is null

    The class toggle-content is there, as I use the same HTML code as UncleCheese. What can be wrong ?

    Thanks in advance,
    Juan

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: [SOLVED] Drill down on frontpage Link to this post

    I find it myself!

    I had to wrap the jQuery code as recommended in http://doc.silverstripe.org/doku.php?id=jquery

    ;(function($) {
    $(document).ready(function() {
       $('.toggle-content').hide();
       $("a[@rel=toggle]").click(
          function() {
             $(this).toggleClass("open");
             $("#toggle-content-" + this.id.replace('toggle-','')).slideToggle("fast");
             return false;
          }
       );
    })
    })(jQuery);

    I would like to know why that worked, since I have already added $(document).ready without success…

    2439 Views
Page: 1 2 3
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.