Skip to content

Instantly share code, notes, and snippets.

@ToddG
Created May 8, 2011 17:06
Show Gist options
  • Save ToddG/961504 to your computer and use it in GitHub Desktop.
Save ToddG/961504 to your computer and use it in GitHub Desktop.
example of a dynamic list
%% -*- mode: nitrogen -*-
-module (abc).
-compile(export_all).
-include_lib("nitrogen_core/include/wf.hrl").
-include("records.hrl").
main() -> #template { file="./site/templates/bare.html" }.
title() -> "Hello from abc.erl!".
% Binding data stored in a simple list.
get_data() -> [
["1", "Title 1", "Author 1", "Description 1", {data, 1}],
["2", "Title 2", "Author 2", "Description 2", {data, 2}],
["3", "Title 3", "Author 3", "Description 3", {data, 3}]
].
get_map() ->
%% Binding map is positional...
[
ordinal@text,
titleLabel@text,
authorLabel@text,
descriptionLabel@text,
myButton@postback
].
body() ->
Data = get_data(),
Map = get_map(),
[
#panel { style="margin: 50px 100px;", body=[
#span { text="Hello from abc.erl!" },
#p{},
#button { text="Click me!", postback=click },
#p{},
#panel { id=placeholder },
#span { text="My dynamic list!" },
#panel { id=toddpanel, body=[
#list { body=[
#bind { data=Data, map=Map, body=[
#listitem { id=titleLabel }
]
}]}
] }
]}
].
event(click) ->
wf:insert_top(placeholder, "<p>You clicked the button!").
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment