Helma logo
helma.org » Home > docs > tutorial > Custom Macros

Custom Macros

The way we filled the MySQL database with some data is quite unefficient. Why not do it with Helma?

As a first step, we enable editing the database entries and add an appropriate link to the skin file Person/link.skin (in a later step we also will make it possible to create new entries):

<a href="mailto:<% this.email %>"><% this.firstname %> <% this.lastname %></a> 
<small><a href="<% this.href action="edit" %>">edit</a></small><br />
Other than the first three macros, this.href does not refer to a property of a person HopObject. It is a custom macro that needs a macro handler, ie. a function to work:

apps/addressbook/Person/macros.js:
function href_macro(param) {
  return(this.href() + param.action);
}
Enter the above lines in a new file and save this as macros.js in the Person directory.

Now let's put it altogether:

Helma transforms the macro structure <% this.href action="edit" %> into a function call of this.href_macro(param) with param being a generic object containing the property action (along with its value).

That means param.action contains the string "edit" as it was assigned in the macro structure. The function href_macro(param) then returns the URL of the actual person HopObject plus "edit".

A look at the browser will proove if these considerations are right:

Hannes Wallnöfer edit
Robert Gaggl edit
Tobi Schäfer edit


Great! It works. But yet the links lead into Helmatic nirvana. We have to enable the edit form, first.


Up: Tutorial
Previous: Improvements Next: Handling User Input

... comment


Page last modified on 2002-04-23 16:48 by czv

 
klemens, Wednesday, 30. April 2008, 15:48
would prefer:

function href_macro(param) {
return(this.href(param.action));
}

... link  


... comment