You are not logged in Log in Join
You are here: Home » Members » Chui Tey » How to pass parameters to a dtml method

Log in
Name

Password

 

How to pass parameters to a dtml method

Introduction

This how-to takes you through creating a dtml-method which takes a parameter, and calling it.

DTML Method

Create a dtml method with:

  • id: dtmlStudent

Code:

    Student Name: <dtml-var student_name>  

Calling the method

Create a dtml-method with:

  • id: dtmlDisplayStudent
  • Title: How To Example

Code:

      <dtml-var standard_html_header>
      <dtml-var "dtmlStudent(_.None, _, student_name='Harry')">
      <dtml-var standard_html_footer>

Yes, the bit with ...var dtmlStudent(.None, , ... looks ugly and complicated, and you may not even find it necessary to use every time. For example, you can get away with dtmlStudent(student_name='Harry). I found using the canonical form consistently better and as your programming skills develop, you find that the syntax above will save you a lot of grief.

Alternative (new April 10, 2002)

I was alerted by an unknown reader that the following code works too. I haven't tested it, but it should work, since the current dtml page's namespace is passed to dtmlStudent in the call.

Code:

      <dtml-var standard_html_header>
        <dtml-let student_name="'Harry'">
          <dtml-var dtmlStudent>
        </dtml-let>
      <dtml-var standard_html_footer>