Sunday, July 29

Geek

Applets, Libraries And Functions (In No Particular Order)

Some of the features discussed in this article are included in the forthcoming 1.1 release. If you try to use these features in 1.0, they probably won't do anything.

The problem with a hosted service like mee.nu is that you can't extend it with plugins.  You certainly can't upload your own PHP files, at least, not if you expect them to do anything.  Minx templates are very flexible and reasonably easy to work with, but they don't make it simple to use a piece of code someone else has designed.

Or they didn't - until now.

[def]
[call]

One of the (previously) undocumented features of Minx is template functions. You can define a function in a template like so:
[def comment]
<tr [if comment.even]bgcolor="#f8f4e0"[/if]>
<td>[comment.authorlink]</td>

...

[/def]
And then call it like so:
[comments count=20 order=desc show=junk paged]
[call comment]
[/comments]
You can pass in parameters the same way you can with templates... which is another undocumented feature:
[include EditorSettings text Text]
Which are substituted into the template (or function... basically the same thing) as indicated by markers of the form {1}, {2} and so on for the first, second, and so onth parameter:
<td align="right"><label for="{1}">&nbsp;&nbsp;{2}</label></td>
Functions, once defined, persist and can be re-used whenever you want. That brings us to the first and simplest of the new features, libraries.

[library]

A library is simply a template that contains a set of functions. Libraries do not produce any output directly, but the functions can be used by any other templates, sub-templates, or applets that you use.

Libraries can be called from another site if the library is flagged as shared. A library will only ever be included once in your template; multiple references to the same library will be skipped.

The process of including a library cannot change global template variables, though the library can read global variables and create local variables. The library can read and update user options.

Calling a library creates a library object, which can be examined both within the library and in the template that called the library.

[applet]

An applet is again just a template with restrictions. As described in the previous post, an applet can be called from another site, and cannot change global variables or template functions.

(I stopped and measured the overhead of an applet vs. a regular template on the test environment. It's about 20μs.)

Apart from producing output in your page, an applet also returns an applet object.  Applets can also read and update user options.  (More on that subject shortly.)

Posted by: Pixy Misa at 10:32 PM | Comments (2) | Add Comment | Trackbacks (Suck)
Post contains 408 words, total size 4 kb.

1

Pixy, the log-in problems at Chizumatic are back... I'm having to log in twice a day now.  Error message is: Comments are only allowed for registered users.

As with last time, all my other 'log-in cookies' are still working fine.

Posted by: Wonderduck at Monday, July 30 2007 01:33 AM (8nB5X)

2 Hmm.  I'm not sure yet what's doing this, but I'll keep checking.

Posted by: Pixy Misa at Monday, July 30 2007 06:06 AM (PiXy!)

Hide Comments | Add Comment

Comments are disabled. Post is locked.
49kb generated in CPU 0.0228, elapsed 0.1042 seconds.
56 queries taking 0.0955 seconds, 328 records returned.
Powered by Minx 1.1.6c-pink.