Hi,

I'm curious about what method folks use to combine several templates into a single web page. The <tmpl_include> syntax obviously addresses this. But it seems tempting in some cases to create a new HTML::Template object for each template and include its output into a single "master" template as a parameter, rather than via <tmpl_include>.

I imagine this is somewhat more expensive than includes. Significantly so? Particularly in a CGI environment? Other downsides?

In a nutshell, it seems like this approach makes template maintenance easier by reducing duplication and, probably, the overall amount of template markup:

1) Encapsulation of parameters for reuse of templates.
For example, I'd like to create a single template that handles form generation. But if I want to include several forms in a page (and they don't stack up nicely enough to fit a <tmpl_loop> pattern), then I can't use the same form template via <tmpl_include> because, of course, the template would use the same parameters for all three instances. But if I generate the html beforehand via several different $tmpl->output calls and pass that result to a template in parameters, then I can reuse the same template.

2) Nesting templates to reduce duplication within templates
Generating included values via separate template objects lets me do something like this:
a) Create html for two forms with a single form template.
b) Include the forms as parameters to a screen/runmode template.
c) Include the html of the runmode template into a master "wrapper" template.

Some simple templates to illustrate that last example example...

** Master template:
    <html>
        <head>
        <title>
            <tmpl_var name="page_title">
        </title>
        </head>
        <body>
        <h1>
            <tmpl_var name="page_title">
        </h1>

        <tmpl_var name="page_content">

        </body>
    </html>
----------
** The "page_content" parameter gets generated by the appropriate screen/runmode template:
    <div id="column1">
        <tmpl_var name="intro_text">
        <tmpl_var name="form1">
    </div>

    <div id="column2">
        <tmpl_var name="form2">
    </div>
----------
** The "form1" and "form2" parameters get generated by the same form template:
    <form action="<tmpl_var name="action_url">" method="post">
        <tmpl_var name="form_title">
        <tmpl_loop name="fieldset">
            <div class="fieldset">
            <h2><tmpl_var name="category_name"></h2>
                <tmpl_var name="category_description">

                <tmpl_loop name="fields">
                    ... generate input fields ...
                </tmpl_loop>

            </div>
        </tmpl_loop>
    </form>

Thanks for your thoughts and advice!
Josh



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Html-template-users mailing list
Html-template-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/html-template-users

Reply via email to