Issue
I'm getting started with CakePHP 3.0 and I'm getting stuck on some code location issues. I installed this plugin to integrate Twitter Bootstrap: https://github.com/elboletaire/twbs-cake-plugin I've copied Layout/default.ctp into my main Layout folder and it's working wonderfully, except I'm not sure where to put my Navbar code.
The layout contains this section where the Bootstrap navbar is set up:
<div class="navbar-header">
<?php if ($this->fetch('navbar.top')): ?>
<button data-target="#navbar-top" data-toggle="collapse" type="button" class="navbar-toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<?php endif; ?>
<?=$ this->Html->link(Configure::read('App.name'), '/', ['class' => 'navbar-brand']); ?>
</div>
<?php if ($this->fetch('navbar.top')): ?>
<nav role="navigation" class="collapse navbar-collapse" id="navbar-top">
<ul class="nav navbar-nav">
<?=$ this->fetch('navbar.top'); ?>
</ul>
</nav>
<?php endif; ?>
I know I need to set navbar.top, but I can't figure out where to set it. My attempt to set it from initialize() in AppView.php using:
$this->set('navbar.top', '<li>Hello</li>');
didn't do anything, and I have no idea where else would make sense to put a universal navbar.
I have no problem just putting it into the template, but the code in the default layout for the Bootstrap plugin seems to suggest otherwise.
Can someone help me figure out where I am supposed to set up the Bootstrap navbar code so it's accessible to my default layout? Thanks so much!
Solution
Put the nav bar inside the element folder.
In layout call element
echo $this->element('navbar.top');
Answered By - Sudhir
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.