This question about Not sure...: Asked

Using different template in a topic

Hello

I am using foswiki for my electronic lab journal.

On a regular basis, I have to create a topic that will be in general with different tables, which are very common. So I created each table with the names eg. Table1Template, Table2Template etc. When I create a new topic I have a possibility to select a template but not two. I would like to know If it is possible to have the freedom to add another template later (which is actually a standard table) to the same topic.

Eg. The final new topic page should contain any two standard tables like below

Table1 (I created a Table1Template with the below table)
   
   

Table2 (I created a Table2Template with the below table)
   
   
Please also let me know if there is another easy way to do this.

Thank you very much.

-- DumbMostly - 31 Jan 2020

I'm not completely sure I understand your intent so correct me if I'm off-base. When you use the term "template", are you using it in the sense of TemplateTopics - i.e. topics used to pre-populate new topics with content? If so, one option would be to create more than one template with different numbers of tables in them.

It sounds more like you really want one basic topic template but then have the ability to add multiple tables (of one or more formats) to a topic as needed. If this the case, I think there are better ways to go about it then TemplateTopics. One idea would be to use CommentPlugin which has the ability to insert content into a topic. In this use case, you would create a custom comment template that inserts one of your selected table templates into the topic. You could possibly add the comment prompt (which could simply be a button) to your sidebar, which would allow you to add a table to any topic you're viewing. Does this make sense? Let me know if you need further help in how to implement this.

-- LynnwoodBrown - 31 Jan 2020 - 17:23

TemplateTopics are only used once when the topic is created initially.

What you might refer to would be a way to insert predefined snippets into the topic as you edit it, such as inserting a table with a specific number of columns and headers, or insert a specific list of things to check off, etc.

That's actually an missing feature not available in Foswiki.

-- MichaelDaum - 31 Jan 2020

One further comment, I hope you have noticed that feature in NatEditPlugin that provides for inserting a table into topic during editing.

-- LynnwoodBrown - 31 Jan 2020

I wanted something like MichaelDaum mentioned. Sad that such a possibility is not there.

-- DumbMostly - 03 Feb 2020

Patches welcome big grin

-- MichaelDaum - 03 Feb 2020

Dear LynnwoodBrown, I would like to try custom comment template as you mentioned but could you please help me out by giving an example. Thank you very much.

-- DumbMostly - 03 Feb 2020

Ok, I've created a small prototype of what I proposed at InsertTableCommentTemplate with a demo of it in action at InsertTableCommentDemo. Since the content of the Sandbox web gets cleared out periodically, here's the relevant code for future reference:

Comment template definition:
%TMPL:DEF{PROMPT:insert_table}%<div class="commentPlugin commentPluginPromptBox"><select name='comment_type'><option value='tabletype1'>Table Type 1</option><option value='tabletype2'>Table Type 2</option>&nbsp;<input %DISABLED% type="submit" value="%button|Add table%" class="foswikiButton %TMPL:P{ajax}%" /></div><!--/commentPlugin-->%TMPL:END%

%TMPL:DEF{OUTPUT:tabletype1}%%POS:BOTTOM%
| *Header 1* | *Header 2* |
|  |   |
|  |   |
---
%TMPL:END%

%TMPL:DEF{OUTPUT:tabletype2}%%POS:BOTTOM%
| *Header 1* | *Header 2* | *Header 3* |
|  |   |   |
|  |   |   |
|  |   |   |
---
%TMPL:END%

Comment macro for using above template:
%COMMENT{ 
   type="insert_table" 
   templatetopic="{web.topic containing comment template}" 
   target="%BASEWEB%.%BASETOPIC%" 
   button="Add Table" 
}%

My though was that you could put the comment macro into a sidebar which would allow you to insert a selected table template into the end of any topic being view.

Let me know if you have any more questions about this. Good luck with your project!

-- LynnwoodBrown - 03 Feb 2020

 

QuestionForm edit

Subject Not sure...
Extension
Version
Status Asked
Related Topics
Topic revision: r8 - 03 Feb 2020, LynnwoodBrown
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