<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Alfa Jango Blog &#187; PHP</title>
	<atom:link href="http://www.alfajango.com/blog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alfajango.com/blog</link>
	<description>Engineering, Software, and Entrepreneurship</description>
	<lastBuildDate>Thu, 09 Sep 2010 17:52:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Include Your Rails App Layout in Your Wordpress Theme (or any PHP application)</title>
		<link>http://www.alfajango.com/blog/how-to-include-your-rails-app-layout-in-your-wordpress-theme-or-any-php-application/</link>
		<comments>http://www.alfajango.com/blog/how-to-include-your-rails-app-layout-in-your-wordpress-theme-or-any-php-application/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 22:31:48 +0000</pubDate>
		<dc:creator>steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[integration]]></category>

		<guid isPermaLink="false">http://www.alfajango.com/blog/?p=68</guid>
		<description><![CDATA[Here's the problem: You have a Ruby on Rails application and its Wordpress blog. For the sake of consistency and branding, you'd like to use the same layout in your Wordpress blog as you do for your Rails app. Perhaps your blog is one of the main links or tabs in your application's header.]]></description>
			<content:encoded><![CDATA[<p>
<strong>Here&#8217;s the problem:</strong> You have a <a href="http://rubyonrails.org/">Ruby on Rails</a> application and its <a href="http://wordpress.org/">Wordpress</a> blog. For the sake of consistency and branding, you&#8217;d like to use the same layout in your Wordpress blog as you do for your Rails app. Perhaps your blog is one of the main links or tabs in your application&#8217;s header.
</p><p>
<img class="size-full wp-image-133 alignnone" title="rails-wordpress-link" src="http://www.alfajango.com/blog/wp-content/uploads/2010/02/rails-wordpress-link.jpg" alt="" width="500" height="233" />
</p><p>
<strong>Why this doesn&#8217;t work:</strong> You proceed with creating a custom theme for your Wordpress blog that looks exactly like your Rails application. Then over the next couple years, you begin to realize how tedious this solution is. You have to copy over your CSS stylesheets from your Rails app, your Javascript files (if your standard layout contains any Javascript elements, like a Twitter widget in the footer or whatever), and your layout images and assets. Then, every time you change or update the layout of your Rails app, you have to copy the changes in your custom Wordpress theme. And you cannot just copy the changes, because if you have any Ruby/Rails functionality in the layout, you have to translate them into PHP functionality in your Wordpress layouts.
</p><p>
And then there&#8217;s the impossible stuff&#8230; if anything in your Rails app layout loads information from the database in your Rails app, then you cannot have those elements in your Wordpress layout, unless you do something like create an XML or JSON feed in your Rails app and then import it in your Wordpress layout. But this is quite tedious still if you want to change any of it!
</p><p>
There&#8217;s an easier way.
</p>
<h3>Include Your Rails Layout Directly In Your Wordpress Layout</h3>
<p>
The solution I found turns out to be quite simple. The basic idea is to create a <code class="codecolorer rails default"><span class="rails"><span style="color:#ff3333; font-weight:bold;">:partial</span></span></code> in your Rails app layout, make it publicly accessible via your <code class="codecolorer text default"><span class="text">config/routes.rb</span></code>, have it generate and simply return the appropriate html using your controller method, and then import that html (and CSS) in your Wordpress layout.
</p>
<span id="more-68"></span>
<p>
For this to really work well, you&#8217;ll want to make sure that you make your Rails app cache the partials to be imported into your Wordpress layout, so that a lot of traffic on your blog doesn&#8217;t cause your Rails app server to explode.
</p>
<h3>1. Break Your Rails Layout into Partials</h3>
<p>
The first step is to break as much of your <code class="codecolorer text default"><span class="text">app/views/layouts/application.html.erb</span></code> into partials as possible/desired. At the very least, this means a header and a footer partial. Typically, you would not include the stuff in the <code class="codecolorer html4strict default"><span class="html4strict"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span></span></code> part of the layout, because your Wordpress will likely require additional stylesheets and a different set of javascripts (not to mention you&#8217;ll want to make your meta information specific for your blog pages).
</p><p>
A simple Rails layout using this method would look something like this:
</p><p>

<div class="codecolorer-container rails twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'&gt;<br />
&lt;html&gt;<br />
&nbsp; &lt;head&gt;<br />
&nbsp; &nbsp; ...<br />
&nbsp; &lt;/head&gt;<br />
&nbsp; &lt;body&gt;<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">render</span> <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'static/header'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &lt;div id=&quot;content&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#9966CC; font-weight:bold;">yield</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &lt;/div&gt;<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">render</span> <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'static/footer'</span><span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">render</span> <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'static/widgets'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &lt;/body&gt;<br />
&lt;/html&gt;</div></div>

</p><p>
I&#8217;ve also included a widgets partial to show that this can be done with static javascript widgets as well.
</p><p>
Note that your layout and partials can have any and all Ruby/Rails code in them that you want. Since your Wordpress theme is importing this stuff from your Rails application, the Rails app will run as usual and just return the end result, which is HTML, so your Wordpress will have no problem interpreting it.
</p><p>
A simple <code class="codecolorer text default"><span class="text">app/views/static/_header.html.erb</span></code> partial may look something like this:
</p><p>

<div class="codecolorer-container rails twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;div id=&quot;header&quot;&gt;<br />
&nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">link_to</span> <span style="color:#5A0A0A; font-weight:bold;">image_tag</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;layout/my_logo.png&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, root_path, <span style="color:#ff3333; font-weight:bold;">:alt</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;My Rails App&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;banner_logo&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &lt;div id=&quot;menu&quot;&gt;<br />
&nbsp; &nbsp; &lt;ul&gt;<br />
&nbsp; &nbsp; &nbsp; &lt;li&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">link_to</span> <span style="color:#996600;">&quot;Products&quot;</span>, products_path, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'active'</span> <span style="color:#9966CC; font-weight:bold;">if</span> request.<span style="color:#9900CC;">path</span> == products_path<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &lt;/li&gt;<br />
&nbsp; &nbsp; &nbsp; &lt;li&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">link_to</span> <span style="color:#996600;">&quot;Blog&quot;</span>, blog_path, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'active'</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@blog</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &lt;/li&gt;<br />
&nbsp; &nbsp; &nbsp; &lt;li&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">link_to</span> <span style="color:#996600;">&quot;Contact&quot;</span>, contact_path, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'active'</span> <span style="color:#9966CC; font-weight:bold;">if</span> request.<span style="color:#9900CC;">path</span> == contact_path<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
&nbsp; &nbsp; &nbsp; &lt;/li&gt;<br />
&nbsp; &nbsp; &lt;/ul&gt;<br />
&nbsp; &lt;/div&gt;<br />
&lt;/div&gt;</div></div>

</p><p>
Notice that the normal links in the header are &#8220;active&#8221; simply if the current URL matches the link path, but the &#8220;Blog&#8221; link is active if the <code class="codecolorer ruby default"><span class="ruby"><span style="color:#0066ff; font-weight:bold;">@blog</span></span></code> variable is set and true. This is because, as you will see in the next section, the URL for the header when it is called from your blog won&#8217;t be the blog URL.
</p>
<h3>2. Make Your Layout Partials Publicly Accessible</h3>
<p>
The next step is to make your layout partials publicly accessible. I.e. make it so that you can access your layout partials from the browser using a direct URL, like http://mysite.com/static/header. The actual URL you use doesn&#8217;t really matter, because users won&#8217;t ever need to see or use it.
</p><p>
The way we do this is to explicitly set a path for each layout partial in our <code class="codecolorer text default"><span class="text">config/routes.rb</span></code> and then create a controller method for each that renders the HTML generated by the partial.
</p><p>
A path in your routes for your header partial might look like this:
</p><p>

<div class="codecolorer-container rails twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC00FF; font-weight:bold;"><span style="color:#6666ff; font-weight:bold;">ActionController::Routing</span></span>::Routes.<span style="color:#9900CC;">draw</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>map<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; ...<br />
&nbsp; <span style="color:#9900CC;">map</span>.<span style="color:#9900CC;">header_partial</span> <span style="color:#996600;">'static/my_blog_header'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'static'</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'blog_header_partial'</span><br />
&nbsp; ...<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>

</p><p>
Then in the <code class="codecolorer text default"><span class="text">app/controllers/static_controller.rb</span></code>, your corresponding action would look like this:
</p><p>

<div class="codecolorer-container rails twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">def</span> blog_header_partial<br />
&nbsp; <span style="color:#0066ff; font-weight:bold;">@blog</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
&nbsp; <span style="color:#5A0A0A; font-weight:bold;">render</span> <span style="color:#ff3333; font-weight:bold;">:partial</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'static/header'</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>

</p><p>
Now, hopefully you see why, in the header partial, we couldn&#8217;t just say that the blog menu item is <code class="codecolorer rails default"><span class="rails">:<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'active'</span> <span style="color:#9966CC; font-weight:bold;">if</span> request.<span style="color:#9900CC;">path</span> == blog_path<span style="color:#006600; font-weight:bold;">&#41;</span></span></code>. The path that the header partial will be seeing when the Wordpress layout requests it will be the path you defined in your <code class="codecolorer text default"><span class="text">routes.rb</span></code>, in this case <code class="codecolorer text default"><span class="text">&quot;static/header&quot;</span></code>. This is why we instead say <code class="codecolorer rails default"><span class="rails">:<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'active'</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@blog</span><span style="color:#006600; font-weight:bold;">&#41;</span></span></code> and then set <code class="codecolorer ruby default"><span class="ruby"><span style="color:#0066ff; font-weight:bold;">@blog</span> = <span style="color:#0000FF; font-weight:bold;">true</span></span></code> in the controller action.
</p>
<h3>Include the Rails Partials In the Wordpress Layout</h3>
<p>
Here&#8217;s the real trick. In order to include the Rails partials in your Wordpress layout, you might be inclined to use on of these PHP functions: <a href="http://php.net/manual/en/function.include.php"><code class="codecolorer php default"><span class="php"><span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code></a> or <a href="http://www.php.net/manual/en/function.require.php"><code class="codecolorer php default"><span class="php"><span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code></a>. This won&#8217;t work though for two reasons.
</p><p>
1) <a href="http://php.net/manual/en/function.include.php"><code class="codecolorer php default"><span class="php"><span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code></a> and <a href="http://www.php.net/manual/en/function.require.php"><code class="codecolorer php default"><span class="php"><span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code></a> both read <code class="codecolorer text default"><span class="text">.php</span></code> files. However, your publicly-accessible layout partials are going to return straight HTML.
</p><p>
2) By default, neither method allows absolute URLs due to security precautions. You can change your PHP setup to allow this, but again, this is a security issue. Not to mention, for our purposes, you still would have to deal with reason 1 above.
</p><p>
Instead, we can use PHP&#8217;s function to retreive HTML code, <a href="http://us.php.net/manual/en/function.file-get-contents.php"><code class="codecolorer php default"><span class="php"><a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code></a>.
</p><p>
In your wp-content/themes/my_theme/header.php file, you would then include this line:
</p><p>

<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">...<br />
&lt;body&gt;<br />
&nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://myrailsapp.com/static/my_blog_header&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$a</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
...</div></div>

</p>
<h3>Import the Rails CSS Stylesheet for Wordpress</h3>
<p>
Of course, you&#8217;ll also want to import the base stylesheet that styles your layout HTML for your Wordpress theme. You can do this a few different ways. The easiest is to just include it in your <code class="codecolorer text default"><span class="text">header.php</span></code> file in the <code class="codecolorer text default"><span class="text">&lt;head&gt;</span></code> area like any other stylesheet, just using the absolute URL to the CSS file.
</p><p>

<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">...<br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/link.html"><span style="color: #000000; font-weight: bold;">link</span></a> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://myrailsapp.com/stylesheets/style.css&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/link.html"><span style="color: #000000; font-weight: bold;">link</span></a> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?php bloginfo('stylesheet_url'); ?&gt;</span></span>&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;<br />
...</div></div>

</p><p>
Notice that we include the Rails app stylesheet before the blog stylesheet. This is so that it&#8217;s easy to override any of the styles we need to specifically in the blog stylesheet.
</p><p>
An alternative way we can do this is using the CSS <code class="codecolorer css default"><span class="css"><span style="color: #a1a100;">@import</span></span></code> method.
</p>
<h3>Cache the Layout Partials On Your Rails Server</h3>
The astute programmer in you may have noticed by now that this turns a single request on your blog into multiple additional requests on your Rails app server (one additional request per partial that&#8217;s imported in your Wordpress layout, e.g. header, footer, etc.). We can&#8217;t have that!
<p>
Luckily this is easy to fix with <a href="http://railsenvy.com/2007/2/28/rails-caching-tutorial#pagination">Rails&#8217;s built-in page-caching</a>.
</p><p>
In your <code class="codecolorer text default"><span class="text">app/controllers/static_controller.rb</span></code> file, include the following.
</p><p>

<div class="codecolorer-container rails twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> StaticController <span style="color:#006600; font-weight:bold;">&amp;</span>lt; ApplicationController<br />
&nbsp; caches_page <span style="color:#ff3333; font-weight:bold;">:index</span>, <span style="color:#ff3333; font-weight:bold;">:blog_header_partial</span>, <span style="color:#ff3333; font-weight:bold;">:blog_header_footer</span>, <span style="color:#ff3333; font-weight:bold;">:blog_widgets</span><br />
&nbsp; ...<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>

</p><p>
And make sure that caching is turned on in your production app, in <code class="codecolorer text default"><span class="text">config/environments/production.rb</span></code>:
</p><p>

<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">...<br />
<span style="color:#9900CC;">config</span>.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">perform_caching</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
config.<span style="color:#9900CC;">action_view</span>.<span style="color:#9900CC;">cache_template_loading</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
...</div></div>

</p>
<h3>And/Or Cache Your Wordpress Pages (recommended)</h3>
<p>
Of course, if you <a href="http://wordpress.org/extend/plugins/wp-super-cache/installation/">install and setup caching in your Wordpress installation</a> (highly recommended), then the complete layout files will be cached and never even need to make calls to your Rails application after the cached pages are generated the first time. This is even faster for your Wordpress blog, because it&#8217;ll load faster now that it doesn&#8217;t have to import portions of the layout from an external URL every time a page is loaded.
</p><p>
Note that when you do this, you&#8217;ll need to expire/delete the cached Wordpress files anytime you update the layout in your Rails app.
</p>
<h3>Done!</h3>
<p>
Now you have a great looking Wordpress blog that looks like you&#8217;re never leaving your Rails application. And best of all, you don&#8217;t have to tediously duplicate efforts every time you update your Rails app layout! How&#8217;s that for <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">DRY</a> design?
</p>]]></content:encoded>
			<wfw:commentRss>http://www.alfajango.com/blog/how-to-include-your-rails-app-layout-in-your-wordpress-theme-or-any-php-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
