This question about Developing extensions (plugins skins etc.): Answered

How can I add an image to every page?

Hi *

I'm new to foswiki, discovering and enjoying it. I looks limitless. I wanted to start making extensions, and for starters, I tried with what I thought it would be a simple one.

I wanted insert an image in every page, even new pages. For every page, the image should be http://something.org/image/_the_name_of_the_foswiki_page. If the image is not found, then nothing should be added.

(the whole story is: I have a network monitoring system, that serves graphs via http. I would like to have a foswiki where I can write about the servers/services monitored, and have the graph as the first element in every server/service monitored. So If I go to http://something/foswiki/Main/yahoo_ping_lost, I want http://something/images/yahoo_ping_lost as the first item in the page ).

I would like to avoid having to put a macro every time I start a new page, so I think I have to use a callback. But I'm not really sure where. I read some plugins, but I don't understand them completely.

Can anyone point me to a plugin on which I can base mine, or maybe tell me the best way to insert the image? Any pointer or idea is much appreciated.

Thanks for foswiki, -- Diego


One way to do this is with a custom view template. This can be set manually for a topic or web by adding: (Commented here with the #)

* #Set VIEW_TEMPLATE = MyView

The view template then contains the <img tag to insert the image based upon the topic name. the "MyView" corresponds to a topic named MyViewTemplate ... note that the template suffix is omitted. This topic would contain:

%TMPL:INCLUDE{"view"}%

%TMPL:DEF{"content"}%
<img alt="" src="%PUBURL%/images/%TOPIC%" />
%TEXT%

%TMPL:END%

Unfortunately this is absolute and will result in a broken image if the file is not available.

If the topics have a form attached, you can also use the AutoViewTemplatePlugin to automatically associate an alternate view with a topic based upon the attached form. That's how the Foswiki Extensions and Tasks web applications work.

-- GeorgeClark - 21 Jul 2011

QuestionForm edit

Subject Developing extensions (plugins skins etc.)
Extension
Version Foswiki 1.1.3
Status Answered
Related Topics
Topic revision: r2 - 21 Jul 2011, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy