I'm getting ready to update a website and I'm thinking about using oocss. I know there are a lot of mixed opinions about oocss, but so far it seems like a good choice for my project. The only thing I dislike about it is the use of tags in the HTML to style complex modules. The oocss documentation says to use some sort of scripting to insert these tags, making them easier to remove down the road when they are no longer necessary, but it doesn't go into any detail how to do this. If anyone could point me to a solution or more information about how to implement this, I would appreciated it. My site is written with asp in c# and i will be using razor templates. I would also like to achieve this server-side, not with java-script, if possible. Thanks.
This is a sample of the html for a complex module:
<div class="mod complex">
<b class="top"><b class="tl"></b><b class="tr"></b></b>
<div class="inner">
<div class="bd">
<p>Lorem ipsum.</p>
</div>
</div>
<b class="bottom"><b class="bl"></b><b class="br"></b></b>
Thanks to Mark I looked around for some html helper examples and found this post.
I modified the code a little so my helper looks like:
public class Complex : IDisposable
{
private readonly ViewContext _viewContext;
private bool _disposed = false;
public Complex(ViewContext viewContext)
{
_viewContext = viewContext;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
_disposed = true;
_viewContext.Writer.Write(
@"</div>
<b class=""bottom""><b class=""bl""></b><b class=""br""></b></b>
</div>"
);
}
}
}
public static class HtmlExtensions
{
public static Complex Complex(this HtmlHelper htmlHelper)
{
htmlHelper.ViewContext.Writer.Write(
@"<div class=""mod complex"">
<b class=""top""><b class=""tl""></b><b class=""tr""></b></b>
<div class=""inner"">"
);
return new Complex(htmlHelper.ViewContext);
}
}
And then in my view I included:
@using (Html.Complex())
{
<div class="bd">
<p>Lorem ipsum.</p>
</div>
}
But now is there a way to include a css class in the view so that it is put into the first div's classes? I'm sorry if this is a stupid question but I very new to C# and MVC in general. This is what I've got so far:
I changed the static class html.extensions to this:
public static class HtmlExtensions
{
public static Flow Flow(this HtmlHelper htmlHelper, string classname)
{
htmlHelper.ViewContext.Writer.Write(@"<div class="" " + classname + @"mod complex flow"">
<b class=""top""><b class=""tl""></b><b class=""tr""></b></b>
<div class=""inner"">"
);
return new Flow(htmlHelper.ViewContext);
}
}
And I put this in my view:
@using (Html.Flow("bgtest"))
{
<div class="bd">
<div style="height:442px; width:980px; background-color: grey;"></div>
</div>
}
I get this error: CS1501: No overload for method 'Flow' takes 0 arguments.