Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Are you talking about adding it to the layout from a view? Because the view is rendered before the layout, meaning that if you create a Helper that would take care of the rendering of style blocks, that would solve your issue.</p> <p>Meaning, that in your view or your viewcomponent, you would be able to invoke something like this:</p> <pre><code>$Style.Add("/static/style1.css") </code></pre> <p>and in your layout (head-section):</p> <pre><code>$Style.Render() </code></pre> <p>Here is an example helper (inheriting AbstractHelper is optional):</p> <pre><code>public class StyleHelper : AbstractHelper { private readonly HashedSet&lt;string&gt; sheets = new HashedSet&lt;string&gt;(); public void Add( string styleSheet ) { Add( styleSheet, "all" ); } public void Add( string styleSheet, string media ) { this.sheets.Add( String.Format( "media=\"{0}\" href=\"{1}\"", media, styleSheet ) ); } public string Render() { var str = new StringBuilder(); this.sheets.ToList().ForEach( sheet =&gt; str.AppendLine( String.Format( "&lt;link rel=\"stylesheet\" {0} /&gt;", sheet ) ) ); return str.ToString(); } } </code></pre> <p>AbstractHelper is part of Castle.Monorail.Framework.Helpers. You do not need to inherit that unless you want to utilize the functionality exposed by that abstract implementation. Then, add it to your controller, either your basecontroller or a specific controller:</p> <pre><code>[Helper( typeof( StyleHelper ), "Style" )] public class YourController </code></pre>
 

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