Jump to:

3397 Posts in 978 Topics by 854 members

Template Questions

SilverStripe Forums » Template Questions » Displaying DataObject properties in a template

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

Page: 1
Go to End
Author Topic: 1852 Views
  • baba-papa
    Avatar
    Community Member
    279 Posts

    Displaying DataObject properties in a template Link to this post

    Hello,

    I implemented the search of dataobjects to my site. The search works, here is the search form´s action method:

    function doSearch($data, $form) {
    $StudioPostcodeQuery = $data['StudioPostcodeQuery'];
    $id = $this->ID;
    $StudioSearchResults = DataObject::get('FitnessStudio', "FitnessStudio.campaignID = '$id' AND FitnessStudio.postcode = '$StudioPostcodeQuery'");
    $data = array(
    'Results' => $StudioSearchResults,
    'Title' => 'Surchergebnisse'
    );
    return $this->customise($data)->renderWith(array('StudioSearch_results', 'Page'));
    }


    The results template looks like this:

    <div class="typography">
    $Title
       <% if Results %>
        <ul id="SearchResults">
    <li>hrhrhr</li>
    <li></li>
        </ul>
        <% else %>
        <p>No results found.</p>
        <% end_if %>
    </div>


    How can I call attributes of the dataobjects in the results template?

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Displaying DataObject properties in a template Link to this post

    <% control StudioSearchResults %>
    <li> $StudioPostcode</li>
    <% end_control %>

    ?

    Neem een kijkje naar de Page_results.ss.. ehm
    Take a look to the default Search method in the BlackCandy theme...

  • baba-papa
    Avatar
    Community Member
    279 Posts

    Re: Displaying DataObject properties in a template Link to this post

    Thanks Martijn,

    I simply forgot the <% control Results %>. Now I can access all dataobject properties. Thanks for your quick help.

    1852 Views
Page: 1
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.