# \[ANN\] cs/Template 0.1.2

**URL:** <https://rubytalk.org/t/ann-cs-template-0-1-2/12198>\
**Category:** ruby-talk\
**Created:** [19 June 2004 00:40 UTC](https://rubytalk.org/t/ann-cs-template-0-1-2/12198 "2004-06-19T00:40:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_O\_Dell1](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@Sean\_O\_Dell1](https://rubytalk.org/u/Sean_O_Dell1)\
**Post date:** [19 June 2004 00:40 UTC](https://rubytalk.org/t/ann-cs-template-0-1-2/12198/1 "2004-06-19T00:40:20Z")

</div>

cs/Template 0.1.2

> **···**
>
> ====================
> 
> cs/Template is a fast, generic text templating engine for Ruby, written in C.  
> Merge native Ruby data structures with text templates to produce final  
> documents. Data structures may be any combination of Hashes, Arrays and  
> Objects (works great with YAML input). Produces any type of text document.  
> Place variables or eval statements anywhere in templates with path-like  
> addressing, control block execution with if/then/else and generate looping  
> blocks of text.
> 
> project homepage: [http://rubyforge.org/projects/cstemplate/](http://rubyforge.org/projects/cstemplate/)  
> download url: [http://rubyforge.org/frs/?group\_id=276&release\_id=549](http://rubyforge.org/frs/?group_id=276&release_id=549)
> 
> # Example code
> 
> require "[celsoft.com/template](http://celsoft.com/template)"  
> require "yaml"
> 
> template = Template::Document.new
> 
> template.data = YAML::load \<\<-END  
> ---  
> author:  
> &nbsp;&nbsp;name : Dallas Diegler  
> &nbsp;&nbsp;email: [whack@mole.com](mailto:whack@mole.com)  
> title : Interesting things I've done  
> type : leaflet  
> END
> 
> template.load \<\<-END  
> ${var title}  
> &nbsp;&nbsp;&nbsp;&nbsp;A ${var type} by ${var author/name}  
> &nbsp;&nbsp;&nbsp;&nbsp;email: ${var author/email}  
> END
> 
> print(template.output)
> 
> &nbsp;&nbsp;Sean O'Dell

---

<div class="post-metadata">

**Author:** ![daz](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@daz](https://rubytalk.org/u/daz)\
**Post date:** [19 June 2004 01:33 UTC](https://rubytalk.org/t/ann-cs-template-0-1-2/12198/2 "2004-06-19T01:33:20Z")

</div>

Sean O'Dell wrote:

> author:  
> &nbsp;&nbsp;name : [...]

&nbsp;&nbsp;&nbsp;&nbsp;name : Sean O'Dell

Just a small nit-pick but many people know enough to be  
able to spot that mistake.

I thought to avoid using alternatives that came to mind.

daz

---

<div class="post-metadata">

**Author:** ![Carsten\_Eckelmann](https://avatars.discourse-cdn.com/v4/letter/c/ba9def/32.png) [@Carsten\_Eckelmann](https://rubytalk.org/u/Carsten_Eckelmann)\
**Post date:** [23 June 2004 00:43 UTC](https://rubytalk.org/t/ann-cs-template-0-1-2/12198/3 "2004-06-23T00:43:20Z")

</div>

Hi,

very nice template library! I like it because the syntax is xml agnostic (one thing that turns off of Amrita). I like because it is fast!

Having the ${eval ...} macro is a fine thing, but how can I access the template data from the eval'd ruby code? Can I even change the data in an eval block?

Cheers,

Carsten.

---

<div class="post-metadata">

**Author:** ![Sean\_O\_Dell1](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@Sean\_O\_Dell1](https://rubytalk.org/u/Sean_O_Dell1)\
**Post date:** [23 June 2004 02:13 UTC](https://rubytalk.org/t/ann-cs-template-0-1-2/12198/4 "2004-06-23T02:13:48Z")

</div>

You can make the template object a class @@variable, instance @variable or a  
global $variable and then you have access to it, and the template#data  
method, or you can call template#resolve to use paths to get at your data.

Perhaps I can figure out how to call the eval in the context of the template  
itself so ${eval} always has access to @data.

&nbsp;&nbsp;Sean O'Dell

> **···**
>
> On Tuesday 22 June 2004 17:43, eckelmann wrote:
> 
> > Hi,
> > 
> > very nice template library! I like it because the syntax is xml agnostic  
> > (one thing that turns off of Amrita). I like because it is fast!
> > 
> > Having the ${eval ...} macro is a fine thing, but how can I access the  
> > template data from the eval'd ruby code? Can I even change the data in  
> > an eval block?
