This package adds File Picker and Multiple File Picker data types to Umbraco 7.
They can be configured to list files from a specific folder, or search recursively, and filter for specific patterns.
The user can then select one, or more with the MultipleFilePicker, file and save. This package will not actually do anything with the file, but your custom template code can use the selected file as needed.
An optional link can be added to open the file, and an edit link that executes javascript. To trigger the internal editor for css or javascript files use one of these values.
Css Edit Link: parent.openStylesheet("{0}");
Javascript Edit Link: parent.openScriptEditor("{0}");
An example to let editors select and attach additional Css and Js files to a document:
Extra Css Data Type:
Starting Folder: /css
Search Pattern: *.css
Alias on Document Type: cssInclude
Extra Script Data Type:
Starting Folder: /scripts
Search Pattern: *.js
Alias on Document Type: jsInclude
// Template code to inject extra resources into ClientDependency. Script and Link tags could also be rendered directly.
@using ClientDependency.Core
@using ClientDependency.Core.Controls
@using Newtonsoft.Json.Linq;
var cdl = Context.GetLoader();
var allDependencies = ;
foreach(var item in GetFileList()) {
cdl.RegisterDependency(item.Priority, item.FilePath, item.PathNameAlias, item.DependencyType);
}
@functions
{
List<IClientDependencyFile> GetFileList()
{
var allDependencies = new List<IClientDependencyFile>();
int priority = 20;
if(Model.Content.HasProperty("cssInclude") && !String.IsNullOrEmpty(Model.Content.GetPropertyValue<string>("cssInclude"))) {
foreach(var item in Model.Content.GetPropertyValue<JArray>("cssInclude"))
{
allDependencies.Add(new CssInclude { PathNameAlias = "Styles", FilePath = (string)item, Priority = priority++ });
}
}
priority = 20;
if(Model.Content.HasProperty("jsInclude") && !String.IsNullOrEmpty(Model.Content.GetPropertyValue<string>("jsInclude"))) {
foreach (var item in Model.Content.GetPropertyValue<JArray>("jsInclude"))
{
allDependencies.Add(new JsInclude { PathNameAlias = "Scripts", FilePath = (string)item, Priority = priority++ });
}
}
return allDependencies;
}
}
Bugs