MindTouch Developer Center > DekiScript > Samples/FAQ > How do I... Embed automatically an attached file?
Table of contents
No headers

An easy way to share files, is to attach them to pages and then embed them directly into the wiki page itself.  The benefit is that it only requires someone to upload a new version of the file to automatically update the page as well.

The following script checks if an attachment exists, and if does, embeds it using a syntax highlter.

{{ 
    var files = map.values(page.files); 
    if(#files > 0) { 
        syntax.xml(web.text(files[0].uri))
    } else {
        "no file(s) attached"
    }
}}

Sample output:

<extension>
  <title>MindTouch iFrame Extension</title>
  <copyright>Copyright (c) 2008 MindTouch, Inc.</copyright>
  <uri.help>http://wiki.developer.mindtouch.com/MindTouch_Deki/Extensions/iFrame</uri.help>
  <label>iFrame</label>
  <description>This extension contains a function for embedding &lt;iframe&gt; elements.</description>

  <function>
    <name>iframe</name>
    <description>Embed an iframe element.</description>
    <param name="uri" type="uri">The iframe URI.</param>
    <param name="width" type="num" optional="true">The iframe width. (default: 425)</param>
    <param name="height" type="num" optional="true">The iframe height. (default: 350)</param>
    <param name="scrolling" type="bool" optional="true">Allow scrollbars inside the iframe. (default: no)</param>
    <param name="frameborder" type="num" optional="true">Frame border thickness on the iframe. (default: 0)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <body>
          <iframe src="{{args.uri}}" width="{{web.size(args.width ?? 425)}}" height="{{web.size(args.height ?? 350)}}" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="{{args.frameborder ?? 0}}" scrolling="{{args.scrolling ? 'yes' : 'no'}}"/>
        </body>
      </html>
    </return>
  </function>
</extension>

 

Tag page

Files 1

FileSizeDateAttached by 
 iframe.xml
sample XML file
1325 bytes15:51, 17 Aug 2008SteveBActions
You must login to post a comment.
Powered by MindTouch Deki v.8.08.1a