Adding custom Capture helpers in base views

Usage:
@using(Capture(html => Layout.Content.Add(x))) {
  <div>foo</div>
}

And

@using(Capture(Layout.Content)) {
  <div>foo</div>
}

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2013-04-19 10:50:17 -07:00
parent 6dd3989c40
commit 68cf505426
2 changed files with 8 additions and 0 deletions

View File

@@ -175,6 +175,10 @@ namespace Orchard.Mvc.ViewEngines.Razor {
return new CaptureScope(this, callback);
}
public IDisposable Capture(dynamic zone, string position = null) {
return new CaptureScope(this, html => zone.Add(html, position));
}
class CaptureScope : IDisposable {
readonly WebPageBase _viewPage;
readonly Action<IHtmlString> _callback;

View File

@@ -121,6 +121,10 @@ namespace Orchard.Mvc {
return new CaptureScope(Writer, callback);
}
public IDisposable Capture(dynamic zone, string position = null) {
return new CaptureScope(Writer, html => zone.Add(html, position));
}
public class CaptureScope : IDisposable {
private readonly HtmlTextWriter _context;
private readonly Action<IHtmlString> _callback;