Forum OpenACS Q&A: suppress errors in templates

Collapse
Posted by Jeff Rogers on
Is there a way to hide error output from template processing?  In particular, I'd like to not have an error message show up with an <include> tag if the source is missing.

More detail:  I'm putting together a sort of dynamic templating system, where a template includes a list of other sub-templates, determined at runtime.  The included sub-templates could of course do the same, and well, you get the idea. The list of sub-templates would come from the database, and the main template page would have something like:

<list name="subtemplates">
  <include src="@subtemplates:item@>
</list>

However, if a particular subtemplate is not found, it outputs an error message "No script or template found for [whatever]".  Obviously, the best thing is to prevent missing templates from getting into the include list, but just in case I'd like to prevent this ugliness from reaching users.

Collapse
Posted by Torben Brosten on
You could use the tcl file exists to check for the existence of the template before running it.

If the list of templates doesn't change after startup, then you could run this once and store the results with the subtemplates references.

cheers,

Torben

Collapse
Posted by Jeff Rogers on
I assume you mean to filter the list of subtemplates in the .tcl file corresponding to the template. But what file would I be looking for? Is there a proc to find the .adp and .tcl files for a particular named template, relative to another template?
Collapse
Posted by Torben Brosten on
Jeff,

When you reference a template in an include, you're using the file pathname reference.

Using your example, if subtemplates:item has a value of my-unique-template-for-this-one-user-this-afternoon then you could check for its existence by adding the openacs root dir to the filepath name:

\[file exists "\[acs_root_dir\]\$subtemplates:item\].tcl"
\[file exists "\[acs_root_dir\]\$subtemplates:item\].adp"

..the pathname might need some tweaking.. but there it is.

These could be scanned one at runtime, since you're defining the templates prior to startup.

FYI, depending on how you're doing this, you might be opening your system up to some security issues. You don't want to give users direct access to specifying template names.

cheers,

Torben