# New Radiant extension: File Based Layout

**URL:** <https://www.ruby-forum.com/t/new-radiant-extension-file-based-layout/109751>\
**Category:** Radiant CMS\
**Created:** [July 18, 2007, 4:55pm UTC](https://www.ruby-forum.com/t/new-radiant-extension-file-based-layout/109751 "2007-07-18T16:55:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casperfabricius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@casperfabricius](https://www.ruby-forum.com/u/casperfabricius)\
**Post date:** [July 18, 2007, 4:55pm UTC](https://www.ruby-forum.com/t/new-radiant-extension-file-based-layout/109751/1 "2007-07-18T16:55:16Z")

</div>

Hi,

As I am building hybrid Radiant/Rails apps, I have had a great need  
to share the same layout between the Rails app and the Radiant pages.  
I have built an extension that allows Radiant Layouts to refer to a  
traditional Rails layout (.rhtml-file).

The extension can be downloaded from [http://svn.casperfabricius.com/](http://svn.casperfabricius.com/)  
extensions/file\_based\_layout/. The text below is a detailed  
description from the README file.

Best regards,  
Casper F.

* * *

= File Based Layout

This extension allows pages served by Radiant to share a standard  
file-based Rails layout with Rails-generated pages. Full ERb can be  
used as normal in the layout, however, Radiant tags cannot currently  
be used in the layouts.

Tested with Radiant 0.6.2

== Installation

1. Place this extension in the RAILS\_ROOT/vendor/extensions/  
file\_based\_layout directory
2. Run % rake db:migrate:extensions

== Usage

You must have a Rails layout file ready in the app/views/layouts/  
directory of Radiant or an extension.

=== The Rails layout (.rhtml) file

There are no special requirements to the layout file. It contain  
anything a normal Rails app will accept.

The body page part is always rendered where it says \<%= yield %\> in  
the layout. Other page parts are rendered where they yielded by their  
name.

For instance, the page part “extended” are rendered where the layout  
says \<%= yield :extended %\>.

=== The Radiant Administration interface

Create a new layout from the “Layouts tab”. Click the “More” link  
below the “Name” text-box, and select a layout file. Any contents in  
the “Body” text area will be ignored.

Any page that has this new Layout, or has inherited the layout, will  
now render using the selected Rails layout file.

== Changes made by this extension

- layout\_file field added to the Layouts table
- file\_based? method added to the Layout model
- SiteController’s show\_uncached\_page method overridden to render  
using a file-based layout, or normal
- Render methods added to SiteController (eventually forwarding to  
Page’s render methods), to be able to map various page parts to  
different content snippets in the layout
- LayoutController’s new and edit method changed to supply list of  
layout files to the view
- Layout File drop-down list added to the Layout edit view  
(overridden by the extension)
