set_content()
Usage
set_content(file, content[, encoding = "UTF-8"])
Description
Overwrites the contents of the given file with the given content.
Note
The encoding
parameter is used when writing the data to the file. The default (UTF-8
) rarely needs to be changed but can be very useful when working with binary strings. For example when using the to_excel()
function.
Example
-
Simply overwrite file with static content
set_content(first(find('File', 'name', 'test.txt')), 'New Content Of File test.txt')
-
Create new file with Excel content
set_content(create('File', 'name', 'new_document.xlsx'), to_excel(find('User'), 'public'), 'ISO-8859-1')
-
Create a new file and retrieve the last 100 tweets from @structr
You first need to create a Twitter application and a corresponding bearer token (see https://developer.twitter.com/en/docs/basics/authentication/api-reference/token for more information)( add_header('Authorization', 'Bearer <YOUR PERSONAL BEARER TOKEN GOES HERE>'), set_content(create('File', 'name', 'structr-tweets.json'), GET('https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=structr&count=100')) )