6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Haxeのテンプレートシステムが便利。

Last updated at Posted at 2012-10-30

Haxeにはテンプレートシステムという便利な機能があります。
あらかじめ、テンプレートを用意しておき変数や関数を挿入して文字列を生成することができます。

Main.hx
import haxe.Template;
class Main {
	static public var template:Template = new Template( "My name is ::name::." );
	static function main() {
		var str = template.execute( { name: "Tanaka" } );
		trace( str );	//My name is Tanaka.
		str = template.execute( { name: "Suzuki" } );
		trace( str );	//My name is Suzuki.
	}
}

HTMLやXMLなどとの相性がよさそうなので、HaXe/JSなんかで役に立ちそうです。
さらにテンプレート内に条件分岐やループを仕込んだり、関数を呼び出させるなど、もっと複雑な使い方もできます。

詳しくはこちらから http://haxe.org/doc/cross/template

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?