I need to create a section on the site where the client can upload documents such as images, pdf, docs whatever. Anyone got any good solution for this, or where to start?
I'm assuming you want to list the documents on the front-end? If you just want to upload them, then you can just use the media library..
If you want a front-end document list, your best bet is to allow editors to upload files to the media library in folders, then allow editors to pick a folder as the basis for the document library.
The following macro (which I will package up soon, with a few additions), works as follows:
* In the developer section, Right-click on "xslt" and create new, leaving the "create macro" box checked * paste the xslt below into the new xslt file and save * Still in the developer section, go up to "macros", expand and find your new macro. * In this screen, select "use in editor" * In the "macro parameters" tab, add a new parameter of type "mediaCurrent" and give it an alias of "startNode" * Save. You're now done, and can use the macro from within the wysiwyg
And in use it goes as follows
* Editors upload files to the media library within folders (nested folders can be used) * When editing a page, they click on "insert macro", choose this one and select a start node in the media library * A document list appears
And more:
* Each list item in the document list is given a class with the extension of the file, to enable prettifying the doc list * If you add a field of alias "fileDescription" to your "file" mediatype, this macro will list the info in the document list * If the macro encounters a folder under the start node, it will write out the folder name as a header and create a nested document list * The filesize of each item in the library is listed in a readable format (not bytes!)
<xsl:choose> <xsl:when test="current()/@nodeTypeAlias='Folder'"> <li> <!-- If this is a folder, call this again --> <h4 class="mediaFolder"><xsl:value-of select="current()/@nodeName" /></h4> <xsl:call-template name="writeList"> <xsl:with-param name="startNode" select="current()" /> </xsl:call-template> </li> </xsl:when> <xsl:otherwise>
<!-- When does this expire? If no expiry set, make it expire in the year 2999 (which should be a good year) --> <xsl:variable name="expiresOn"> <xsl:choose> <xsl:when test="string(string(./data[@alias='docExpireDate'])) != ''"> <xsl:value-of select="./data[@alias='docExpireDate']" /> </xsl:when> <xsl:otherwise> <xsl:text>2999-11-10T00:00:00</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:variable>
<!-- if the current file isn't expired, write the list item and file info --> <xsl:if test="umbraco.library:DateGreaterThanToday($expiresOn)"> <li> <xsl:attribute name="class"><xsl:text>file </xsl:text> <xsl:value-of select="current()/data [@alias='umbracoExtension']" /> </xsl:attribute> <h5> <a target="_blank" href="{current()/data [@alias='umbracoFile']}"> <xsl:value-of select="current()/@nodeName" /><xsl:text> </xsl:text> (<xsl:call-template name="FileSizeKb"> <xsl:with-param name="fileSize" select="current()/data [@alias='umbracoBytes']" /> </xsl:call-template>) </a> </h5> <xsl:if test="string(current()/data [@alias='fileDescription']) != ''"> <p class="file_description"><xsl:value-of select="current()/data [@alias='fileDescription']" /></p> </xsl:if> </li> </xsl:if>
@Dan : When i copy paste your xslt i get this error?
/// code ///
System.OverflowException: Value was either too large or too small for an Int32. at System.Convert.ToInt32(Double value) at System.Double.System.IConvertible.ToInt32(IFormatProvider provider) at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType) at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args) at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current) at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results) at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter) at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results) at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results) at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results) at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)
<xsl:choose> <xsl:when test="current()/@nodeTypeAlias='Folder'"> <li> <!-- If this is a folder, call this again --> <h4 class="mediaFolder"><xsl:value-of select="current()/@nodeName" /></h4> <xsl:call-template name="writeList"> <xsl:with-param name="startNode" select="current()" /> </xsl:call-template> </li> </xsl:when> <xsl:otherwise>
<!-- When does this expire? If no expiry set, make it expire in the year 2999 (which should be a good year) --> <xsl:variable name="expiresOn"> <xsl:choose> <xsl:when test="string(string(./data[@alias='docExpireDate'])) != ''"> <xsl:value-of select="./data[@alias='docExpireDate']" /> </xsl:when> <xsl:otherwise> <xsl:text>2999-11-10T00:00:00</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:variable>
<!-- if the current file isn't expired, write the list item and file info --> <xsl:if test="umbraco.library:DateGreaterThanToday($expiresOn)"> <li> <xsl:attribute name="class"><xsl:text>file </xsl:text> <xsl:value-of select="current()/data [@alias='umbracoExtension']" /> </xsl:attribute> <h5> <a target="_blank" href="{current()/data [@alias='umbracoFile']}"> <xsl:value-of select="current()/@nodeName" /><xsl:text> </xsl:text> (<xsl:call-template name="FileSizeKb"> <xsl:with-param name="fileSize" select="current()/data [@alias='umbracoBytes']" /> </xsl:call-template>) </a> </h5> <xsl:if test="string(current()/data [@alias='fileDescription']) != ''"> <p class="file_description"><xsl:value-of select="current()/data [@alias='fileDescription']" /></p> </xsl:if> </li> </xsl:if>
Unfortunately I can't get the package working. I'm using the recent version of the XSLT and after following the steps on how to inlclude the macro in the editor, the page is blank.
Create a "Mediabank, Document Bank"
I need to create a section on the site where the client can upload documents such as images, pdf, docs whatever.
Anyone got any good solution for this, or where to start?
Some kind of preview of the file solution?
Hi Jonas
Can't the client use the media-section? In there it is possible to upload a lot of different files such as, png, jpg, pdf, flv, doc etc.
/Kim A
Hi Jonas, and welcome to our.
I'm assuming you want to list the documents on the front-end? If you just want to upload them, then you can just use the media library..
If you want a front-end document list, your best bet is to allow editors to upload files to the media library in folders, then allow editors to pick a folder as the basis for the document library.
The following macro (which I will package up soon, with a few additions), works as follows:
* In the developer section, Right-click on "xslt" and create new, leaving the "create macro" box checked
* paste the xslt below into the new xslt file and save
* Still in the developer section, go up to "macros", expand and find your new macro.
* In this screen, select "use in editor"
* In the "macro parameters" tab, add a new parameter of type "mediaCurrent" and give it an alias of "startNode"
* Save. You're now done, and can use the macro from within the wysiwyg
And in use it goes as follows
* Editors upload files to the media library within folders (nested folders can be used)
* When editing a page, they click on "insert macro", choose this one and select a start node in the media library
* A document list appears
And more:
* Each list item in the document list is given a class with the extension of the file, to enable prettifying the doc list
* If you add a field of alias "fileDescription" to your "file" mediatype, this macro will list the info in the document list
* If the macro encounters a folder under the start node, it will write out the folder name as a header and create a nested document list
* The filesize of each item in the library is listed in a readable format (not bytes!)
Dan
Thanks for the welcom and the fast replies! :D
@Kim : I was looking for a more flexible way to manage a mediabank.
@Dan: I will try it out, sounds promising though :)
/Jonas
@Dan : When i copy paste your xslt i get this error?
/// code ///
Hi Jonas
Try to mark the "skip error testing" and see if it works in the frontend.
/Jan
Yeh, the error can safely be ignored or you could wrap the getMedia with an xsl:if, changing
to
Dan
Hi thanks for the replies :)
Now i get this error:
"The variable or parameter 'mediaFolder' is either not defined or it is out of scope."
Tested it with "skip error testing" but it won´t display in the frontend?
I´m really greatful for your help, kinda new to the xslt parts :)
Ooops, perhaps stick the if around the whole start bit, or just revert to the original and skip testing for errors (that's what I do!)
Dan
Wow :D
Thank you so much!
This will be a great package, and I bet alot of people will have good use of it.
Here´s the final working code:
This was exacly what I was looking for.
Unfortunately I can't get the package working. I'm using the recent version of the XSLT and after following the steps on how to inlclude the macro in the editor, the page is blank.
is working on a reply...