Workaround for User Functions in Mobile #453
Replies: 2 comments 6 replies
-
I just found an easier way of doing this, much less hacky 😅 In the template file containing the function you want to export, include the line |
Beta Was this translation helpful? Give feedback.
-
My initial comment was incorrect. See below for an updated version that actually works. Or see @cfritze64 's comment for another working example. The difference between what I initially posted and the working code below is that the sender function needs to store Template file
or for the same result but without defining a full function when one isn't needed, Template file
Template file
(note Then creating a file from
@eb4i to troubleshoot in macOS, use cmd-opt-i to view the console. I don't know how to do it on other platforms, unfortunately |
Beta Was this translation helpful? Give feedback.
-
I just discovered something that made me happy and I would like to share it.
I was disappointed when I found out that currently, user functions are unavailable on mobile. Then I remembered the provided tp.file.include function. I thought maybe I could use it to import a function definition to use in the current template. Alas, it appears to only import the processed output and discards the code. So there is no way to pass arguments to those functions... or is there?
It turns out I can pass arguments as properties of any predefined object (like
tp
) and those properties will be accessible by any template called within the "tp.file.include" statement. Therefore, we can effectively pass arguments to functions like so:Example:
Templates/Greet me by name.md
Templates/Say Hello.md
or equivalently:
Now wherever "Greet me by name.md" is used, it will produce "Hello Ryan". And it works in mobile!
Any valid name can be appended to
tp.
and any value can be assigned to it — just be careful not to overwrite existing members oftp
or you may get unexpected results! Alternatively, you could resolve to always pass arguments as arrays totp.args
or something similar.Beta Was this translation helpful? Give feedback.
All reactions