draxil / node_template

HTML templating for go, with no mess!

Home Page:http://digitalhippy.me.uk/node_template

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node_template

HTML templating for go, with no mess!

node_template extends go.net/html & cascadia to make it as easy as possible to process pure HTML templates. Using jquery like search syntax you can find the elements you wish to populate by looking for the attributes you require. This approach allows HTML templates which are pure HTML.

Example:

func main_page( w http.ResponseWriter, r * http.Request ){
    template, err := node_template.NodeTemplateFromFile( "temp/main.html");

    if( err != nil ){	
        log.Println( err );
        return
    } 

   	title_el, err := template.FindFirst(`#title`);
    if( title_el != nil){
       title_el.ReplaceContentText("Billy & Jane");
    }
    
    names, err := template.Find(`.name`);
    if( names != nil ){
        names.ReplaceContentText("tom");
    }

    var people list.List
    people.PushBack("Tom");
    people.PushBack("Richard");
    people.PushBack("Harry");
    person, _ := template.FindFirst(".person");
    if( person != nil ){
    person.RepeatNode( &people, func( node * node_template.NodeTemplate, e * list.Element  ){
            node.ReplaceContentText( e.Value.(string) );
        });
    }

    template.Render( w );
}

GoDoc Build Status

About

HTML templating for go, with no mess!

http://digitalhippy.me.uk/node_template

License:GNU General Public License v2.0


Languages

Language:Go 99.2%Language:HTML 0.8%