String concatenation

Hello fellow tinkerers,

I want to catalog my 3D models and created tiddlers that have a “files”, a “path” and a “name” field.

I then went on to build a viewTemplate to display a picture for the current model and links to all files specified in the “files” field.

title: model foo
files: scad step
path: modelfoo
name: modelfoo
title: model bar
files: step 3mf
path: bigmodel/internal
name: model bar

Now as you can see, path and/or name do not need to correspond to the title since some models are part of a bigger model. Therefore I need the path and name field.

For every model there is a folder which contains the model files and a .png file for display in TW named identical.

modelfoo
- modelfoo.scad
- modelfoo.step
- modelfoo.png
bigmodel
- internal
-- model bar.m3f
-- model bar.step
-- model bar.png
- external
-- ...

Now we come to my unexpected struggle generating the links:

For the model foo tiddler “path” and “name” are identical which causes substitute to deduplicate breaking the link.

<$set name="baseLink" filter="${[is[current]get[path]]}$/${[is[current]get[name]]}$">
	<$set name="link" filter="[<baseLink>substitute[]] [[.png]] +[join[]]">
		<$image source=<<link>> />
	</$set>
</$set>

I tried another approach using join but that breaks if there are spaces in “name” or “path” like in bigmodel:

<$set name="baseLink" filter="[is[current]get[path]] [[/]] =[is[current]get[name]] +[join[]]">
	<$set name="link" filter="[[$(baseLink)$.png]substitute[]]">
		<$image source=<<link>> />
	</$set>
</$set>

I know, whitespace is evil, but I am not the only one using this and getting “normal” people to not put spaces in file names is neigh impossible.

I am sure I am missing something obvious…

There’s no need to use the substitute[] filter operator. Try this:

<$let baseLink={{{ [{!!path}] =[{!!name}] +[join[/]] }}}>
   <$image source={{{ [<baseLink>] [[.png]] +[join[]] }}}/>
</$let>

This could also be written without defining the baseLink variable (unless you need that for something else), like this:

<$image source={{{ [{!!path}] [[/]] =[{!!name}] [[.png]] +[join[]] }}}/>

-e

2 Likes

Thank you @EricShulman!

My TW setup is rather stable so I am dabbling in rarely these days. If I do I always have to relearn stuff :wink: