Replacement for templater #28
-
|
Came across this plugin today and with it I want to replace some functionality of my other plugins (templater, quickAdd, dataview). First up is my daily note, which now uses templater. I was tinkering with it and could not find a nice solutions without some hick-ups. First of all here is what I tried. I created a template file (Daily.md) with the following in it: My goal is to handle all the logic before the call to
Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Adding a more general question (as it seems to fit with the title of this): is Codescript Toolkit a supposedly (albeit more technical) replacement for Templater? E.g. functionality like merging properties etc. all are highly specific to Templater. I can see that e.g. additional function support would be great in Templater, but would it also work the other way around (having Templater specific functions in |
Beta Was this translation helpful? Give feedback.
-
|
While technically it's possible to get rid of I personally use <%*
import {
fn1,
fn2,
fn3,
fn9
} from '/module.ts';
const var4 = fn1(app);
const var5 = await fn2(app.workspace.getActiveFile(), 'arg6');
-%>
Static content <% var4 %>
Another static content <% var5 %>
Inline function call <% fn3(app) %>
Even inline module, but I don't recommend it, as it's too verbose <% await require('/module7.ts').fn8() %>
<%* for (let i = 0; i < 10; i++) { -%>
Generated line <% i %>: <% fn9(i) %>
<%* } -%>I find it more readable than the example from the topic starter.
If you have a button code at the top of the file (beginning of the file)
```code-button
await codeButtonContext.replaceCodeButtonBlock('---\na: b\nc: 2\n---\n');
```Then frontmatter creation works However, if the button code is not at the top of the file, you cannot rely on naive text replacement then, you need (any place at the beginning of file or not)
```code-button
await app.fileManager.processFrontMatter((fm) => {
fm.key = 'newValue';
fm.key2 = ['list', 'of', 'values'];
});
```
In case you want to write something at cursor you can (any place at the beginning of file or not)
```code-button
await app.workspace.activeEditor.setState({ mode: 'source' }, {});
app.workspace.activeEditor.editor.replaceSelection('new text to insert at cursor');
```
There is no one-line equivalent of it. I don't see much use of it. But will some calculations you can, for example ```code-button
await app.workspace.activeEditor.setState({ mode: 'source' }, {});
app.workspace.activeEditor.editor.setCursor(codeButtonContext.markdownInfo.positionInNote.end.line + 1, 0); // go to line after the code block
```
The button executes only when the note is opened. You can use Remove after execution feature to prevent multiple executions, but if you just created the note, but never opened it, nothing will trigger the code execution. It's possible, but would require some additional coding.
I would not suggest replacing
No, the aim of
If you are using You can have <%*
import { fn } from '/module.ts';
-%>
Text: <% await fn(tp) %>And in interface TemplaterApi {
system: {
clipboard(): Promise<string>;
}
}
export async function fn(tp: TemplaterApi): Promise<string> {
return await tp.system.clipboard();
}If the question was can we access However, in my opinion, |
Beta Was this translation helpful? Give feedback.
@ru-van-urk
While technically it's possible to get rid of
Templaterand replace with this plugin, I would not recommend it as the readability would suffer.I personally use
Templatertogether with the plugin in a wayI find it more readable than the exa…