Reputation: 1291
How do I include the same navigation bar in 2 different layout files? I don't want the navigation bar code to be repeated in the 2 layout files.
The following is my navigation bar code:
<?php
echo $this->Html->css('nav_bar.css');
?>
<script language="javascript" type="text/javascript">
sfHover = function() {
var sfEls = document.getElementById("navbar").getElementsByTagName("li");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" hover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" hover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
</script>
<div id="menu">
<ul id="nav">
<li><?php echo $this->Html->link('Home', '/pages/home', array()); ?></li>
<li><?php echo $this->Html->link('Our Program', '#', array()); ?><ul>
<li><?php echo $this->Html->link('Preschool', '/pages/preschool',
array()); ?></li>
<li><?php echo $this->Html->link('Kindergarten', '/pages/kindergarten', array()); ?></li>
<li><?php echo $this->Html->link('Summer Camp', '/pages/summer_camp', array()); ?></li>
</ul>
</li>
<li><?php echo $this->Html->link('About Us','#', array()); ?><ul>
<li><?php echo $this->Html->link('Merry Flowers', '/pages/about_us', array()); ?></li>
<li><?php echo $this->Html->link('Tour Our School','/pages/tour_our_school', array()); ?></li>
<li><?php echo $this->Html->link('Contact Us', '/pages/contact_us', array()); ?></li>
</ul>
</li>
<li><?php echo $this->Html->link('Events','#', array()); ?><ul>
<li><?php echo $this->Html->link('News & Events', '#', array()); ?>
<ul>
<li><?php echo $this->Html->link('Sports Day','/pages/sports_day',array()); ?></li>
</ul>
</li>
<li><?php echo $this->Html->link('List of Holidays', '/pages/list_of_holidays', array()); ?></li>
</ul>
</li>
<li><a href="#">FAQ</a><ul>
<li><?php echo $this->Html->link('FAQ', '/pages/faq', array()); ?></li>
<li><?php echo $this->Html->link('Feedback', '/feedbacks/add', array()); ?></li>
<li><?php echo $this->Html->link('Discussion', '/pages/discussion', array()); ?></li>
</ul>
</li>
<li><a href="#">Admissions</a><ul>
<li><?php echo $this->Html->link('Enroll Now','/students/add', array()); ?></li>
</ul>
</li>
</ul><!--finish ul nav-->
</div> <!--finish div menu-->
thank you.
Upvotes: 0
Views: 2847
Reputation: 20102
create a file called navbar.ctp in the /views/elements/
in your layout you'll need to include the element using the element()
method of the views:
<?php echo $this->element('navbar'); ?> // you can pass an array of variables as a second parameter
for more, read the doc
Upvotes: 1