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 /

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

Blog Entries in Navigation Dropdown [RESOLVED]


Go to End
Reply


3 Posts   1178 Views

Avatar
VictorH

Community Member, 29 Posts

26 July 2011 at 4:34pm

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

Forum Moderator, 5521 Posts

26 July 2011 at 11:22pm

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

Community Member, 29 Posts

2 August 2011 at 4:12am

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