Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The easiest way to theme a site is to simply link to a different stylesheet. You can do this dynamically using something like:</p> <pre><code># in app/views/layouts/application.html.erb &lt;%= stylesheet_link_tag :application %&gt; &lt;%= stylesheet_link_tag #{current_theme} %&gt; # in app/helpers/application_helper def current_theme # You'll have to implement the logic for a user choosing a theme # and how to record that in the model. # Also, come up with a better name for your default theme, like 'twentyeleven' ;) current_user.theme || 'default' end </code></pre> <p>Then you can have a couple manifests for themes. For example, your assets directory can look something like this:</p> <ul> <li>app/assets/stylesheets <ul> <li>application.css</li> <li>buttons.css</li> <li>theme1/ <ul> <li>index.css</li> <li>buttons.css</li> </ul></li> <li>theme2/ <ul> <li>index.css</li> <li>buttons.css</li> </ul></li> </ul></li> </ul> <p>This will get you started with pure css theming. At some point you'll probably want to also them javascript and html layouts. When you start finding the need to do something like this in your html:</p> <pre><code>&lt;% if current_theme == 'theme1' %&gt; &lt;li&gt;... &lt;% elsif current_theme == 'theme2' %&gt; &lt;b&gt;... &lt;% end %&gt; </code></pre> <p>then it's time to implement a more robust theming framework:</p> <ul> <li>namespace your html templates by theme (e.g. app/views/themes/theme1/users/index.html.erb) and render the themed version instead of the default</li> <li>namespace just the partials by template (e.g. app/views/themes/theme1/users/_form.html.erb) and add a helper method like <code>render_themed_partial</code></li> <li>similar to the above approaches, but when the themes get very large, you should consider putting them into their own gems as rails engines</li> </ul> <p><strong>Note:</strong> This is all for static themes. For dynamic themes (e.g. where an admin can login and edit the stylesheets or html), you'll have to store theming information in the database. Depending on your architecture, you may be able to provide a set of static themes, and then another theme that dynamically grabs styling data from the database. At that point, you're developing a CMS, however, so it's outside the scope of this answer :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload