Value of a (transcluded) empty field?

hi all,
i have a question about how transcluding an empty field. i am making a macro that needs to give the same result in these two cases:

  1. the parameter is empty (like <<mymacro>>)
  2. the parameter transcludes a field which is empty (like <<mymacro {{!!blankField}}>>).

#1 is easy ([<param>else[result]]), and something like [{!!blankfield}is[blank]then[result]] would work for #2, but i need to transclude the field (as opposed to passing its name to the macro as a parameter) so what should i do?

i guess my root question is: how do i use a filter to match the value given by a transcluded empty field?

I may be wrong because I am not sure of your question, but why not as follows;

[{!!blankfield}else[result]] or if it returns blanks, [{!!blankfield}!is[blank]else[result]]

However I tend to use filter in the list widget and rather than set “result”, I tend to make use of the fact if empty the content of the list widget is not displayed;

sorry if the question was unclear, i can try stating it with an example version of the macro (actually a procedure):

\procedure myproc(term flag)
<$let url="https://${[<flag>then[es]else[en]]}$.wikipedia.org/wiki/$(term)$">
    <$wikify name=link text={{{[<url>substitute[]]}}}>
        <a href=<<link>>><<term>></a>
    </$wikify>
</let>
\end

a pretty simple procedure to make a link.

i would like either of these to set the language to en:
<<myproc term>>
<<myproc term {{!!blankField}}>>

and either of these to set the language to es:
<<myproc term anyTextHere>>
<<myproc term {{!!nonBlankField}}>>

despite {{!!blankField}} always transcluding to an empty string, <<flag>> never matches match[] or is[blank] when it is set to {{!!blankField}}… maybe this is due to the way procedures vs. macros interpret transclusions?

Does this get you any closer?

\procedure myproc(term flag)
<$let blank={{{ [<flag>is[blank]then[en]] }}}  url="https://${[subfilter<blank>] :else[<flag>then[es]else[en]]}$.wikipedia.org/wiki/$(term)$">
    <$wikify name=link text={{{[<url>substitute[]]}}}>
        <a href=<<link>>><<term>></a> | <<link>>
    </$wikify>
</$let>
\end 

<$macrocall $name=myproc term=house flag={{!!blankField}} />

<$macrocall $name=myproc term=house flag=“hi” />

Try to get “flag” evaluated before adding it the link address string

2 Likes

and

is invalid wikitext syntax.

With non-literal parameter values like field references you should use <$transclude> as it supersedes now deprecated <$macrocall> since TW v5.3.0:

<$transclude $variable=myproc term=house flag={{!!blankField}} />

or:

which still works.

Hope this helps,

Fred

1 Like

this works, thank you!
but i don’t understand why your solution does anything different than the OP, why does it matter if the filter is evaluated in the <$let> versus in the main filter?
just trying to understand so i can come to similar solutions in the future if needed.

also thanks @tw-FRed also for the help with the procedure call!

If you let the macro/procedure print the “flag” parameter using your original code, you’ll see that you just get plain-text substitution

The filter only sees the literal text {{!!blankField}} as the value for “flag” which makes the flag value not blank.

Using the $let widget is the easiest way I know of to get an intermediate value “wikified” before plugging into a filter so the proper value is used instead of the wikitext used to get that value.

There are probably some finer points that Eric or Mario or Tony could point out, but that was my thinking for my version. Glad I could help :slightly_smiling_face:

@tw-FRed good call, I’m not yet familiar enough will all the new Transclusion options, slowly working them into existing code where I can.

1 Like