2sxc snippets & tricks
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"));
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();
PortalSettings.ActiveTab.FullUrl,
ApplicationPath = (Request.IsSecureConnection ? "https://" : "http://") + PortalAlias.HTTPAlias + "/",
DefaultLanguageID = Sexy != null ? Sexy.ContentContext.GetLanguageId(PortalSettings.DefaultLanguage) : null
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
}
//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
});
edit template -> advanced section -> view name in url -> Details/.*