7.7 #def

The template:

#def printArg($arg)
The argument is $arg.
#end def
My method returned $printArg(5).

The output:

My method returned The argument is 5.
.

Hmm, not exactly what we expected. The method returns a trailing newline because we didn't end the last line with #slurp. So the second period (outside the method) appears on a separate line.

The #def generates a method .printArg whose structure is similar to the main method:

def printArg(self,
        arg,
        trans=None,
        dummyTrans=False,
        VFS=valueFromSearchList,
        VFN=valueForName,
        getmtime=getmtime,
        currentTime=time.time):


    """
    Generated from #def printArg($arg) at line 1, col 1.
    """

    if not trans:
        trans = DummyTransaction()
        dummyTrans = True
    write = trans.response().write
    SL = self._searchList
    filter = self._currentFilter
    globalSetVars = self._globalSetVars
    
    ########################################
    ## START - generated method body
    
    write('The argument is ')
    write(filter(arg)) # generated from '$arg' at line 2, col 17.
    write('.\n')
    
    ########################################
    ## END - generated method body
    
    if dummyTrans:
        return trans.response().getvalue()
    else:
        return ""

When .printArg is called from a placeholder, only the arguments the user supplied are passed. The other arguments retain their default values.