I’m setting up a few CakePHP template files (.ctp) for a controller test. I have /test/index and test/search pages, which uses index.ctp and search.ctp, respectively.
There’s a left-hand size vertical menu section that goes into each of these pages, but it seems redundant and unnecessary to include the same HTML code in every .ctp files that will go under /test/.
The code for this left menu is something like below, and I’d like to avoid copying and pasting it every time I create a new page. Is there a way to load a separate file that includes this code for all .ctp files for the test controller? Or maybe I’m approaching this the improper way? I’m learning off of the default template file that came with CakePHP 1.3 right now.
<div class="actions">
<h3><?php __('Menu'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('Product Search', true), array('action' => 'search')); ?></li>
</ul>
</div>
Also, while I have this question up, what is the significance of class name (“actions”) in the div tag?
You can put the HTML in an element to easily reuse it. Put the HTML you want to reuse in a file located at:
app/views/elements/some_element.ctp. Call it what you want.Then add this to your view or layout files:
echo $this->element('some_element');actionsis just a class. The only significance is what you give it in your css.Using the default Cake CSS and layout,
actionsis a div that floats left, allowing easy access to links generated bybaking.