create new tag
, view all tags

SID-02348: Attachment link - createlink

Status: Answered Answered TWiki version: 6.0.2 Perl version:
Category: CategoryAttachments Server OS: Last update: 2 months ago

I want to put a list in a topic, with links to the attachments of many other topics. Think of a drawing list, with links to a specific revision of an attached drawing file. It takes a lot of time to create links with the format

. So I am looking for a smarter and faster way to do this.

I was thinking of several options:

  • Create a formatted SEARCH with the desired format and use variable expansion to copy the list in my topic. (See Support.SID-00430 Expand Search Results On Template Copy). But this works only if the topics and/or attachments can be found with a logical search, which not often not possible.

  • Generate formatted links in the topics containing the attachments. Copy the link and paste it into the topic containing the drawing list. This link can be created when attaching an attachment ("create link in the topic text"), but: a) can the autogenerated link to the attachment (createlink) be specified, so that the format of the link is the desired format for my drawing list? b) when this link was not created when attaching the file, how do I generate a link to the attachment in the topic text?

Ad a): At TWikiUIUploadDotPm I found: " createlink if defined, will create a link to file at end of topic". But how to define?
Ad b): I was thinking of 'glueing' an attachment link to the topic by using COMMENT, hoping that I was able to put something in the COMMENT frame like

%STARTSECTION{type=expandvariables}%%ATTACHMENTLIST{format="| [[/pub/$fileWeb/$fileTopic/fileName?rev=1]] | |Info/Details |}%%ENDSECTION{type=expandvariables}%
. And that the link to the topic would then be added to the topic. But this isn't going to work.

Any suggestions?

-- Emiel Van Riel - 2018-02-23

Discussion and Answer

Let me check whether I understand you correctly: You want to create a static list of links - and not a dynamic search. This gives a "snapshot" which is not affected when new versions of attachments are uploaded later.

The bad news: You can not create this static list by just editing a topic. The expandvariables thingy from SID-00430 works when a new topic is created from a template. That way, the template content keeps containing the TWiki variables, and every topic created from this template has the expanded stuff. This would be the way to go - or, as an alternative, you can create your own form with a save action.

Generally, for obtaining information about attachments, QuerySearch can help a lot. But still, a %SEARCH{...}% will only ever report the most recent revision of a topic or attachments, so for a snapshot containing fixed versions you indeed need an expanded list.

Ad a): createlink is a true/false value available via a checkbox from the "Attach" page. The actual style of the link is defined by the preference value ATTACHEDFILELINKFORMAT: The default (a bullet list) is defined in TWiki.TWikiPreferences, overriding per web or topic is possible as usual.

Ad b:) I doubt that this can be achieved with CommentPlugin: When evaluating comments on save, TWiki variable expansion is suppressed. The percent sign as well as the less-than and greater-than signs needed for HTML elements are replaced by their corresponding HTML entities. I have been bitten by this many times in my comments smile

-- Harald Jörg - 2018-02-23

Thanks, Harald. With the preference ATTACHEDFILELINKFORMAT at least I can achieve that newly created links have the format I want. I realised myself that using the CommentPlugin will not work, but I was trying to sketch a working method which would be practical to reach my goal. Thinking of this: wouldn't it be nice we could copy parts of topics and paste this in another topic in different ways: a) as TWiki markup; b) as expanded TWiki markup; or c) as plain (rendered) text. (Like in Excel: paste formulas or values or makeup.) Especialliy for a SEARCH it would be helpfull to paste the expanded results as static text, but with links to the topics included.

-- Emiel Van Riel - 2018-02-24

That's quite a challenge you are posting here... copy & paste happens at the client side, without TWiki involved. Here are some things to consider:

  • Pasting stuff into a topic can only be done if the target topic is open in edit mode (either raw or HTML editing).
    • You can paste HTML into a raw edit window, and it will be rendered correctly most of the times. If your users prefer a skin which isn't compatible with the HTML you pasted, they might complain.
    • You can paste HTML into the HTML editor window, but it will only take effect if you format make the section as "protect on save". Otherwise the '<' and '>' will be escaped. Other quirks can happen because the HTML editor tries to "reformat" your HTML into TWiki markup, which is a lossy process. In short: don't do that.
    • You can paste some TWiki markup into the HTML editor window. All line-oriented stuff fails: Bullet or numbered lists, tables. In short: don't do that.
    • You can paste TWiki markup into the raw editor window. This is, in my opinion, the only sane way to do copy & paste.
  • So, the topic you are copying from should display TWiki markup - but somewhere between "raw view" and formatted HTML. You need to be able to "mark" the part you want to copy, and there must not be some "invisible" parts.

In the special case of %SEARCH{...}% you can create results which are suitable for copy & paste into raw edit, by applying some voodoo to the search format. Here are two examples. Note the use of textarea which makes it very convenient to mark the whole stuff:

A table layout:

<textarea cols="60" rows="3">
%SEARCH{"SID-00430" scope="all" nonoise="on" encode="HTML"
         header="| *Topic* | *Version* |" 
         format="| [[$web.$topic?rev=$rev][$topic]] | $rev |"
renders as:

A bullet list:

<textarea cols="60" rows="3">
%SEARCH{"SID-00430" scope="all"
        encode="HTML" nonoise="on" format="   * [[$web.$topic?rev=$rev][$topic]]"
renders as:

-- Harald Jörg - 2018-02-24

Thanks again, Harald. I can use this information very well to make an acceptable workaround.

-- Emiel Van Riel - 2018-02-25

      Change status to:
ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
Status Answered
Title Attachment link - createlink
SupportCategory CategoryAttachments
TWiki version 6.0.2
Server OS

Web server

Perl version

Browser & version

Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r7 - 2018-02-25 - EmielVanRiel
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.