On Tue, Mar 1, 2011 at 4:01 AM, K3 <kiril.zvezdako...@gmail.com> wrote: > Hi, > > if i add another subfolder in /app/view where i want to put > alternative view structure of the site, so for example for articles > folder i have following structure: > > /app/ > /view/ > /_version2/ > /articles/ > /articles/ > > and i have 2 files > /app/view/articles/index.ctp and /app/view/_version2/articles/ > index.ctp > > In general i want to render view from alternative folder if that view > exists. something like: > > if ("/app/view/_version2/xxxxxx/yyyyy.ctp" exists) { > render("/app/view/_version2/xxxxxx/yyyyy.ctp"); > } else { > render("/app/view/xxxxxx/yyyyy.ctp"); > } > > is this possible? > i wanted to add such control in beforeRender, but seems there i can't > control which view to render, only to post variables to the view. Any > thoughts? >
eg. in PostsController, one can do this: $this->viewPath = 'posts/foo'; ... to use templates in app/views/posts/foo/ dir. The fact that we don't need to set $viewPath for every action tells us that it's already set for us. So, it would be possible to use that to check for a commonly-named directory inside whichever is at the end of the current $viewPath. AppController: function beforeFilter() { parent::beforeFilter(); // other stuff if (is_dir(APP.'views'.DS.$this->viewPath.DS.'_version2')) { $this->viewPath .= DS.'_version2'; } } I think this would probably work fine for you although it could become complicated. For example, I often adjust the $viewPath to point to the elements/whatever dir and render just an element when sending back an AJAX response. On the face of it, this shouldn't be too big a problem when used with the example above, but you should keep in mind that there may be other reasons for adjusting $viewPath. If your code has nothing like that going on, you should be fine. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php