jerkovicl
6/8/2015 - 11:52 AM

2sxc snippets & tricks

2sxc snippets & tricks

2sxc snippets:

  • Get first entity for some content type
    var cachedManifest = AsDynamic(App.Data["CachedManifest"].List.First());

  • Enable only for Admin
    @if (Dnn.User.IsInRole(Dnn.Portal.AdministratorRoleName))

  • Get the values for FirstName and see if there is any value in the language fr-FR

  var entity = AsEntity(Content);
  var firstNameIsTranslatedToFrench = entity["FirstName"].Values.Any(v => v.Languages.Any(l => l.Key.ToLower() == "fr-fr"));
  • Get all query strings
var queryStringPairs = Request.QueryString.AllKeys.Select(key => string.Format("{0}/{1}", key, Request.QueryString[key]).ToLower()).ToArray();
var queryStringKeys = Request.QueryString.AllKeys.Select(k => k == null ? "" :  k.ToLower()).ToArray();
  • Dnn oneliners
PortalSettings.ActiveTab.FullUrl,
ApplicationPath = (Request.IsSecureConnection ? "https://" : "http://") + PortalAlias.HTTPAlias + "/",
DefaultLanguageID = Sexy != null ? Sexy.ContentContext.GetLanguageId(PortalSettings.DefaultLanguage) : null
  • Register scripts from code
protected void InsertClientScripts(string scriptUrl, int priority = 100, ScriptLocation scriptLocation = ScriptLocation.Default)
{
    switch (scriptLocation)
    {
        case ScriptLocation.Header:
            ClientResourceManager.RegisterScript(this.Page, scriptUrl, priority, "DnnPageHeaderProvider");
            break;
        case ScriptLocation.BodyTop:
            ClientResourceManager.RegisterScript(this.Page, scriptUrl, priority, "DnnBodyProvider");
            break;
        default:
            ClientResourceManager.RegisterScript(this.Page, scriptUrl, priority, "DnnFormBottomProvider");
            break;
    }
}

public enum ScriptLocation
{
    Header,
    BodyTop,
    Default
}
  • Passing information from Razor client (cshtml) to AngularJS
//embed the following in your razor page:
//Model is a .NET object you want to render.
 <script>
  app.value('myValue', @Html.Raw(Json.Encode(Model)))
 <script>
//Then inject it into your controller:

 app.controller('ctrl', function($scope, myValue) 
 {
      //use myValue
 });
Working solutions
Usefull docs & help files
Tips & Tricks
  • Setup for NewsArticles details page template: edit template -> advanced section -> view name in url -> Details/.*
  • Possible Upgrade fix, change iframe to div on these pages (for .NET 4.5+): Website\DesktopModules\ToSIC_SexyContent\Administration\GettingStarted.ascx Website\DesktopModules\ToSIC_SexyContent\SexyContent\GettingStarted\GettingStartedFrame.ascx
Branko 2sxc snippets