Skip to content

Create a new file based on the current file's title #1000

Answered by welpdx
byerun asked this question in Help
Discussion options

You must be logged in to vote

woohooo discussion #1000!

Try this script:

<%* 
//get title and appends text to the end
const nameVar = tp.file.title + " - " + "address"
//searches for the [[template]] template to add template content
const templateVar = tp.file.find_tfile("template")
//create new file with filename and content from [[template]]
await tp.file.create_new(templateVar, nameVar)
%>

In [[template]]:

%% 
tp.file.title gets the title. 
split() gets the first half before the hyphen. 
trim() removes whitespaces. 
tR is the output, thats why we use \<\%* 
%%
problem: [[<%* tR += tp.file.title.split("-")[0].trim()%>]]

# Solution
Demo

~welp

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@byerun
Comment options

@welpdx
Comment options

@byerun
Comment options

@welpdx
Comment options

Answer selected by byerun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants