Templater
Templater copied to clipboard
User Script Functions are not working on mobile
Plugin informations:
- OS: Android
- Templater version: 1.11.3
- Obsidian version: 1.1.1 (44)
- Templater settings:
- Template: "10 Meta/Templates/testing.md"
- User function: "10 Meta/Templates/Scripts/notice.js"
Content of the template (testing.md):
<%* tp.user.notice(tp) %>
Content of the script (notice.js):
async function notice(tp) {
const text = await tp.system.prompt("What's Good?")
new Notice(text, 5000)
}
module.exports = notice
Describe the bug The function doesn't run with the following error:
[error] Templater Error: Template parsing error, aborting.
tp.user.notice is not a function
Expected behavior The user function runs, displaying a prompt.
Additional context
- I have tested this with other scripts as well, none work.
- The template folder is set to
10 Meta/Templates
- The script folder is set to
10 Meta/Templates/Scripts
- The script is recognised by Tenplater in the settings:
Thanks for the great work with Templater. I'd love to use user functions on mobile too, but always run into an error.
I do have the same problem. If this is a limitation that javascript can not be run from the vault, it should probably be documented in the Documentation.
I am having this same problem.
It seems it is disabled on mobile: https://github.com/SilentVoid13/Templater/blob/master/src/core/functions/user_functions/UserFunctions.ts#L29-L34
It looks like all I needed to do was remove the part about only getting user functions for desktop and it worked for me. I am going to make a PR to get that removed. It may be that iOS had problems or that there is a UT that fails. Here is to hoping there will be no issue with accepting the change.
It looks like all I needed to do was remove the part about only getting user functions for desktop and it worked for me. I am going to make a PR to get that removed. It may be that iOS had problems or that there is a UT that fails. Here is to hoping there will be no issue with accepting the change.
I have this issue, too. I have no clue how I can resolve it using your fix because I’m not very literate, but I guess I will wait until Void sees this so I can use user scripts on Mobile. THANKS!
Testing the fix on iOS and I still can't run user scripts.
So https://silentvoid13.github.io/Templater/user-functions/overview.html is still correct, user defined scripts don't run on mobile?
It works just fine on Android.
Edit: I don't have an iOS device, but it works on Android as I use it frequently on Android.
I just made a user script on iOS, and to my surprise this seemed to work.
I get the following warning:
Templater Error: Template parsing error, aborting. Check console for more information
But the templater command and the user function are all evaluated correctly.
If anyone can tell me how to check the console on iOS I can provide more detailed info.
Plugin informations:
OS: iOS Templater version: 1.18.3 Obsidian version: 1.4.16(114) Templater settings: Template: "/templates/random-reflection-question.md" User function: "Scripts/select_random_line_from_file.js"
Content of the template (random-reflection-question.md):
##
<%_*
fc = await tp.file.include("[[Reflection questions]]");
tR+= " "
tR+= await tp.user.select_random_line_from_file(fc);
-%>
Content of the script (select_random_line_from_file.js):
function getRandomStringFromFileContent(fileContent) {
if (typeof fileContent !== 'string') {
return "Invalid input: Please provide a valid string.";
}
stringList = fileContent.split('\n');
if (!Array.isArray(stringList) || stringList.length === 0) {
return "Invalid input: Please provide a non-empty array of strings.";
}
const randomIndex = Math.floor(Math.random() * stringList.length);
return stringList[randomIndex];
}
module.exports = getRandomStringFromFileContent;
To inspect the iOS app as well as read the console, you need iOS 16.4+ and a Mac. Instructions: https://webkit.org/web-inspector/enabling-web-inspector/