Question
I'm creating some templates for pages that will probably have movie files attached - but not always.
I'd like to include an embed tag automatically on these pages, but only if the movie file is attached.
To make this easier, the movie files will always be named the same thing.
Is there any TWiki function for checking existing attachments? Something I can put in an %IF or calc IF()?
I see calc EXISTS(), but it appears to be for topics, not attachments.
Any guidance would be appreciated!
Environment
--
MahlonSmith - 11 Jan 2007
Answer
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.
We do not yet have a good
ContentAccessSyntax to query meta data easily. I see two ways to work around this:
1. Create a simple plugin (if you know Perl) to expand a custom variable, such as
%ATTACHMENTEXIST{name}%. See
TWikiPlugins.
2. Use SEARCH to
test for an attachment. Do a
FormattedSearch to test if an attachment exist. You can search all meta data with a
VarSEARCH, but you can't format the result.
The meta data of an attachment looks like this: (hint: do a topic view with a
view=debug parameter)
%META:FILEATTACHMENT{name="FooBar.mpg" attachment="FooBar.mpg" attr="" comment="Blah" date="1166511779" path="FooBar.mpg" size="50918" user="Main.PeterThoeny" version="2"}%
So you can SEARCH for it, and format a desired output. If there is no hit, search returns nothing. Untested search:
%SEARCH{ "META\:FILEATTACHMENT\{name\=\"FooBar.mpg\"" topic="%TOPIC%" type="regex" nonoise="on" format="FooBar.mpg found" }%
--
PeterThoeny - 11 Jan 2007
The SEARCH works great for my need - thanks so much!
--
MahlonSmith - 11 Jan 2007
Glad it worked out.
--
PeterThoeny - 11 Jan 2007