1 vote

File Picker Data Type

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;

    }

 

}

Screenshots

Archived files

Documentation

Source code

Package owner

Jeremy Pyne

Jeremy Pyne

Jeremy has 246 karma points

Package Compatibility

This package is compatible with the following versions as reported by community members who have downloaded this package:
Untested or doesn't work on Umbraco Cloud
Version 8.18.x (untested)

You must login before you can report on package compatibility.

Previously reported to work on versions: 7.15.x, 7.5.x

Package Information

  • Package owner: Jeremy Pyne
  • Created: 05/02/2016
  • Current version 1.0
  • .NET version 4.5
  • License MIT
  • Downloads on Our: 473