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.

Template Questions

Blog Entries in Navigation Dropdown [RESOLVED]


Reply

3 Posts   885 Views

Avatar
VictorH

26 July 2011 at 4:34pm Community Member, 29 Posts

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>

Avatar
Willr

26 July 2011 at 11:22pm Forum Moderator, 5511 Posts

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.

Avatar
VictorH

2 August 2011 at 4:12am Community Member, 29 Posts

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