Skip to content

Instantly share code, notes, and snippets.

@sniffdk
Created May 15, 2013 13:30
Show Gist options
  • Save sniffdk/5583994 to your computer and use it in GitHub Desktop.
Save sniffdk/5583994 to your computer and use it in GitHub Desktop.
Sort document type in the dropdownlist when creating a new node in Umbraco.
/* From web.config or some other config place */
<add key="CreateContentSortOrder" value="Content page,Section page,some other page type name" />
/* In /umbraco/create/content.ascx - put the code in the bottom */
<%
var createContentSortOrder = ConfigurationManager.AppSettings["CreateContentSortOrder"];
if (!String.IsNullOrWhiteSpace(createContentSortOrder))
{ %>
<script type="text/javascript">
$(function () {
var sortOrder = <%= "['" + createContentSortOrder.Replace(",", "','") + "']" %>;
var $select = $('select');
var $options = $('option', $select);
$(sortOrder).each(function (i, o) {
$options.each(function () {
var $option = $(this);
if ($option.text() === o) {
$option.appendTo($select);
}
});
});
$options.each(function () {
var $option = $(this);
if (sortOrder.indexOf($option.text()) == -1) {
$option.appendTo($select);
}
});
$select.val($('option:first-child', $select));
});
</script>
<% } %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment