From Newsgroup: comp.lang.tcl
It is a rather silly example, but the secret is that you pass the *name*
of the variables and not the value.
I have refactored the 'render' proc to use 'upvar' and this is turning out to be
more useful in simplifying all 'components',
```
proc render {data css template} {
upvar $data _data
upvar $css _css
upvar $template _template
# Generate scoped CSS and get container class
lassign [scope_css $_css] scoped_css container_class
# Create a container with the scoped CSS
set result [div [list class $container_class] \
[style {} $scoped_css] \
[eval $_template]]
return $result
}
```
as an example here is 'pagination' component,
```
...
dict set data headers {Name Email Status {Last Active}}
set page 1 ;# Current page (default to 1)
set page_size 5 ;# Rows per page
set template {
upvar page _page
upvar page_size _page_size
table {class "pagination-table"} \
[tr {} \
{*}[lmap header [dict get $_data headers] {
th {} $header
}]] \
{*}[lmap row [lrange [dict get $_data rows] [expr {($_page - 1) * $_page_size}] [expr {$_page * $_page_size - 1}]] {
tr {} \
{*}[lmap cell $row {
td {} $cell
}]
}] \
[div {class "pagination-nav"} \
[if {$_page > 1} {
a [list href "/pagination?page=[expr {$_page - 1}]" rel "prev"] "Previous"
}] \
[span {} "Page $_page"] \
[if {$_page * $_page_size < [llength [dict get $_data rows]]} {
a [list href "/pagination?page=[expr {$_page + 1}]" rel "next"] "Next"
}]]
}
return [render data table_pa_styles template]
}
```
--- Synchronet 3.20c-Linux NewsLink 1.2