Forum OpenACS Development: Templating on the fly?

Collapse
Posted by Nima Mazloumi on
Dear all,

is it possible to serve html from the database on the fly containing @...@ parameters?

I want to define a table with a column let's say fragment that contains HTML-Fragments including @...@ parameters. An sql statement show return the apropriate html from database. Now the tricky part is that the HTML contains parameters that should be replaced with values like users.user_id first.

Has anyone an idea or hint how I could do this?

Best wishes,
Nima

Collapse
2: Re: Templating on the fly? (response to 1)
Posted by Jade Rubick on
Nima, I've wanted to do this before too.

Generally what I do is build my own multirow (no by using db_multirow). Then I can put whateveer I like in it.

Collapse
3: Re: Templating on the fly? (response to 1)
Posted by Tom Jackson on

Jade, it sounds like Nima wants to evaluate a chunk of text from the database as a template, or template chunk.

I haven't figured out a way of doing this yet (when it has @a@ or @a.b@ references).

The problem seems to be that evaluating a template produces a chunk of tcl code, it doesn't produce a string ready to return to the connection.

Collapse
4: Re: Templating on the fly? (response to 1)
Posted by Don Baccus on
Returning a string isn't a problem - look at adp_parse_template.

But the template engine expects the template to be stored in the file system ... you can't just pass a string to it (or two strings to it, script and adp).

Collapse
5: Re: Templating on the fly? (response to 4)
Posted by Malte Sussdorff on
How about storing the template in a temporary file system location and letting the template engine fetch it from there. A sweeper could clean up the directory once per day.
Collapse
6: Re: Templating on the fly? (response to 1)
Posted by Nima Mazloumi on
Hi Don, hi Malte,

where can I look for an example to generate files that are stored in the file system? Don't I have to have a .tcl file with the same name as the file that contains the string that comes from the database and is stored locally?

Greetings,
Nima

Collapse
7: Re: Templating on the fly? (response to 1)
Posted by Jun Yamog on
Hi Nima,

Its possible to create data_getter.tcl that gets the value on the db.  And ad_return_template to displayer_1.adp or maybe you want to add logic to use displayer_2.adp.

By not putting ad_return_template foo, it will implicitly  return the current adp pair for you tcl.  You can override this by using ad_return_template.

Collapse
8: Re: Templating on the fly? (response to 1)
Posted by Nima Mazloumi on
Hi Jun,
can you give a minimal example or name a package that does something similar? My knowledge of OpenACS is not so well yet to understand you suggestion properly. ;)

Thank you in advance,
Nima

Collapse
9: Re: Templating on the fly? (response to 1)
Posted by Jun Yamog on
Hi Nima,

You can look at bcms-ui-base on contrib.  But maybe its more complicated that most packages that use ad_return_template.  Try grepping for ad_return_template you will surely get a lot of those.  I think the old bboard has lots of them.

Collapse
Posted by Jade Rubick on
Does this relate at all?

https://openacs.org/bugtracker/openacs/bug?bug%5fnumber=1099

Can it be used for double substitution in OpenACS templates? It looks like it could be used for something, but I have no idea what... What are the implications of this?