Single page design using Orchard CMS

I have a client who wants to create a single page design for his site, where the content of each "page" is displayed / hidden using javascript when the user navigates the site.

I'm not sure how best to approach this with Orchard. One option would be for the content to be contained in one element of the page content, and then you would lose the ability to use the Orchard navigation features and could not allow the client to think about administration in terms of pages.

Does anyone have any ideas or impressions on how best to configure this in Orchard CMS?


Here's the solution I used based on Bertrand's recommendations:

public ActionResult Display(int id)
{
     var contentItem = _contentManager.Get(id, VersionOptions.Published);
     dynamic model = _contentManager.BuildDisplay(contentItem);
     var ctx = _workContextAccessor.GetContext();
     ctx.Layout.Metadata.Alternates.Add("Layout_Null");
     return new ShapeResult(this, model);
}

, . . _contentManager _workContextAccessor . Layout.Null.cshtml , .

+5
3

, , , SEO, : - "" , .. URL-. , Ajax. , , , Ajax ( , , ..), , " ":

var ctx = _workContextAccessor.GetContext();
ctx.Layout.Metadata.Alternates.Add("Layout_Null");
return new ShapeResult(this, shape);

Layout.Null.cshtml , :

@{
    Model.Metadata.Wrappers.Clear();
}
@Display(Model.Content)

document.cshtml, Content. , , . ajax.

?

+8

, FilterProvider/IResultFilter? , . , , , .

- :

public class LayoutFilter : FilterProvider, IResultFilter {
    private readonly IWorkContextAccessor _wca;

    public LayoutFilter(IWorkContextAccessor wca) {
        _wca = wca;
    }

    public void OnResultExecuting(ResultExecutingContext filterContext) {
        var workContext = _wca.GetContext();
        var routeValues = filterContext.RouteData.Values;

        if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest()) {
            workContext.Layout.Metadata.Alternates.Add("Layout_Null");

        }           
    }

    public void OnResultExecuted(ResultExecutedContext filterContext) {
    }        
}
+2

Reusing Rahul's answer with added code to answer @tuanvt's question. I honestly don’t know what your question is, but if it seems to you that you want to access the data sent using the ajax request. If this is JSON, you send set contentType: "application / json" in the request, JSON.stringify (), then access it in Rahul, offering an ActionFilter, extracting it from the request stream. Hope this helps.

public class LayoutFilter : FilterProvider, IResultFilter {
  private readonly IWorkContextAccessor _wca;

  public LayoutFilter(IWorkContextAccessor wca) {
        _wca = wca;
  }

  public void OnResultExecuting(ResultExecutingContext filterContext) {
      var workContext = _wca.GetContext();
      var routeValues = filterContext.RouteData.Values;

      if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest()) {
           workContext.Layout.Metadata.Alternates.Add("Layout_Null");

           if (filterContext.HttpContext.Request.ContentType.ToLower().Contains("application/json"))
           {
                var bytes = new byte[filterContext.HttpContext.Request.InputStream.Length];
               filterContext.HttpContext.Request.InputStream.Read(bytes, 0, bytes.Length);
               filterContext.HttpContext.Request.InputStream.Position = 0;
               var json = Encoding.UTF8.GetString(bytes);
               var jsonObject = JObject.Parse(json);
               // access jsonObject data from ajax request
           }
      }           
  }

  public void OnResultExecuted(ResultExecutedContext filterContext) {
  }        
}
+2
source

All Articles