Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP View change extension

Tags:

cakephp

How can I change the extension for CakePHP Views from .ctp to .php

I have seen there is this line in /cake/libs/view.php var $ext = '.ctp'; that sets the extension but how can I do it from my /app/ folder so it doesn't effect Cake core files.

Thanks

like image 534
Cameron Avatar asked Jan 08 '11 14:01

Cameron


2 Answers

You can set the extension in your AppController with

public $ext = '.yourext';
like image 140
dhofstet Avatar answered Nov 15 '22 17:11

dhofstet


This is is reply to Cameron's comment regarding the issue of using multiple extensions in light of the fact cakephp does not allow you to specify multiple extensions.

I am using Mustache for a single site that uses merb, rails2, rails3 and cakephp for different sections of the site. The cake site "receives" mustache files for common layout elements but these templates have a '.mustache' file extension which my cake site will not recognize. My workaround is basically what dhofstet suggests just framed in the context of your specific usecase. In short, create a wrapper that might look something like this:

<?
  $tmp = $this->ext;
  $this->ext = '.mustache';
?>
<?= $m->render($this->renderElement('moznav/advanced_header'), array('foo' => $bar)) ?><br />

<? $this->ext = $tmp; ?>

When flow returns to the caller, you keep on using your native file extension.

like image 34
ynkr Avatar answered Nov 15 '22 17:11

ynkr