is there a way to check the type of a parameter to select the right routine for output?
I have the following situation:
I have Tiddlers with the tag Department.
AND
I have Tiddlers with fields named Department containing a name like “Human Resources”.
AND
I want to have Tiddlers with fields named Department containing a list of Departments e.g. “[[Sales Department] [Purchasing Team]]” but it is not defined how the list has to be created.
I did some tests with different procedures, but I want to have only one procedure what is doing the right output automatically.
My problem here I do not know how to select the right procedure
AND
I also have no idea what kind of definition I can use to define the list in the field and to list these items.
Here is my code so far.
code-body: yes
tags: $:/tags/Global
title: Display the right content
\whitespace trim
\procedure Display (A_Name)
\procedure show_content_of_field(content_selector)
Field <<content_selector>> :
<$view field=<<content_selector>><br>
\end
\procedure show_list(list_selector)
<$list filter='[<list_selector>]' variable="this_field">
<$view field=<<this_field>>/><br>
</$list>
\end
\procedure show_tagged_tiddlers(tag_selector)
<$list filter='[tag<tag_selector>sort[caption]]' variable="title_of_field">
<$view tiddler=<<title_of_field>> field="caption" /><br>
</$list>
\end
<!-- if A_Name is a tag then <<show_tagged_tiddlers A_Name -->
<!-- OR -->
<!-- if A_Name contains a list then <<show_list A_Name -->
<!-- OR -->
<!-- if A_Name contains not a tag and not a list then <<show_tagged_tiddlers A_Name -->
\end
Having the same variable-name for fundamentally different types is a bad idea. For a tag there is the is-operator, which could be used to identify if a string is used as a tag. But that does not mean that it has be read from a tag.
So if you have a filter like <$list filter ="[tag[HelloThere]]" ... the currentTiddler variable will contain the tiddler titles that are tagged HelloThere. Most of those variables are also used as tags. So <%if [<currentTiddler>is[tag]]%>could be used to identify if it is used as a tag. But it does not know if the value was created by using [tag[HelloThere]]. It could have been created with <$list filter="[list[HelloThere]]".., which is a completely different thing.
So no you can not identify, where a variable did come from The only way is to use proper variable naming.
If a field contains a single value it should be named department – in singular. I personally always start variable names and field-names with lowercase. So I do not need to think about it.
If a field contains list I would name it departments or dep-list which makes it clear that it can contain title lists. Even if the list field only conatains one value.
If you want to create a procedure that does behave differently, depending on what type of value you feed it, you will need to give it a second parameter.
(The code is not tested)
\procedure show(selector, type:"tag")
<% if [<type>match[tag]] %>
<!--> do something -->
<% elseif [<type>match[list]] %>
<!--> do something -->
<% else %>
<!--> do something -->
<% endif %>
/end