mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-31 07:32:59 +00:00 
			
		
		
		
	Enhance rendertiddler command with template option
This commit is contained in:
		| @@ -1,10 +1,10 @@ | ||||
| title: $:/language/Help/rendertiddler | ||||
| description: Render an individual tiddler as a specified ContentType | ||||
|  | ||||
| Render an individual tiddler as a specified ContentType, defaults to `text/html` and save it to the specified filename: | ||||
| Render an individual tiddler as a specified ContentType, defaulting to `text/html` and save it to the specified filename. Optionally a template can be specified, in which case the template tiddler is rendered with the "currentTiddler" variable set to the tiddler that is being rendered (the first parameter value). | ||||
|  | ||||
| ``` | ||||
| --rendertiddler <title> <filename> [<type>] | ||||
| --rendertiddler <title> <filename> [<type>] [<template>] | ||||
| ``` | ||||
|  | ||||
| By default, the filename is resolved relative to the `output` subdirectory of the edition directory. The `--output` command can be used to direct output to a different directory. | ||||
|   | ||||
| @@ -32,9 +32,15 @@ Command.prototype.execute = function() { | ||||
| 		path = require("path"), | ||||
| 		title = this.params[0], | ||||
| 		filename = path.resolve(this.commander.outputPath,this.params[1]), | ||||
| 		type = this.params[2] || "text/html"; | ||||
| 		type = this.params[2] || "text/html", | ||||
| 		template = this.params[3], | ||||
| 		variables = {}; | ||||
| 	$tw.utils.createFileDirectories(filename); | ||||
| 	fs.writeFile(filename,this.commander.wiki.renderTiddler(type,title),"utf8",function(err) { | ||||
| 	if(template) { | ||||
| 		variables.currentTiddler = title; | ||||
| 		title = template; | ||||
| 	} | ||||
| 	fs.writeFile(filename,this.commander.wiki.renderTiddler(type,title,{variables: variables}),"utf8",function(err) { | ||||
| 		self.callback(err); | ||||
| 	}); | ||||
| 	return null; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jermolene
					Jermolene