Jump to:

3434 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » Blog Entries in Navigation Dropdown [RESOLVED]

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

Page: 1
Go to End
Author Topic: 851 Views
  • VictorH
    Avatar
    Community Member
    29 Posts

    Blog Entries in Navigation Dropdown [RESOLVED] Link to this post

    I'm trying to display Blog Entries inside of a Navigation Dropdown but it wont display the blog entries. If I remove it outside the <% control ChildrenOf(main) %> control it works but not anywhere inside.

    Here is the code.

    Page.php

    <?php
    class Page extends SiteTree {
       public static $db = array();

       public static $has_one = array();
    }

    class Page_Controller extends ContentController {
       public static $allowed_actions = array ();

       public function init() {
          parent::init();

          Requirements::themedCSS('layout');
          
          Validator::set_javascript_validation_handler('none');
       }
       
       function LatestBlogEntries($number=4) {
          $holder = DataObject::get_one('OurBlogHolder');
          return DataObject::get('BlogEntry', "ParentID = {$holder->ID}","Created DESC", false, $number);
       }
    }

    Navigation.ss

    <ul id="nav">
    <% control ChildrenOf(main) %>
    <li class="dropTrigger">
       <a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle.XML</span></a>

       <% if Children %>
          <ul id="{$URLSegment}Drop" class="dropdown">
             <% control Children %>
                <% if ClassName = SolutionsSubHolder %>
                   <% control Children %>
                      <li class="{$URLSegment}">
                         <h2><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode">$MenuTitle.XML</a></h2>                           
                         <% if DropdownText %><p>$DropdownText.LimitCharacters(65)</p><% end_if %>
                       </li>
                   <% end_control %>
                <% else %>
                   <li class="{$URLSegment}">
                      <% if DropdownImage %><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><img src="$DropdownImage.URL" alt="" /></a><% end_if %>
                      <h2><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode">$MenuTitle.XML</a></h2>
                      <% if DropdownText %><p>$DropdownText</p><% end_if %>
                      <% if ClassName = OurBlogHolder %>
                         <ul>
                            <% control LatestBlogEntries %>
                               <li><a href="$Link">$MenuTitle</a></li>
                            <% end_control %>
                         </ul>
                         <p><a class="arrowLink" href="">Read More</a></p>
                      <% end_if %>
                   </li>
                <% end_if %>
             <% end_control %>
          </ul>
       <% end_if %>
    </li>
    <% end_control %>
    </ul>

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Blog Entries in Navigation Dropdown [RESOLVED] Link to this post

    I think one issue is you need to put the 'LatestBlogEntries' function from your Controller class (Page_Controller) into the Model class (Page). When you're inside a control like that you're in 'scope' of the model, not the controller.

  • VictorH
    Avatar
    Community Member
    29 Posts

    Re: Blog Entries in Navigation Dropdown [RESOLVED] Link to this post

    Thank you Willr. This fixed the issue I was having.

    851 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.