<?xml version="1.0" encoding="windows-1252"?>
<node id="454980" title="Free Nodelet gets templating features" created="2005-05-08 03:23:15" updated="2005-08-11 12:55:40">
<type id="1036">
monkdiscuss</type>
<author id="22609">
tye</author>
<data>
<field name="doctext">
&lt;p&gt;
I've hacked together some quick enhancements
for the Free Nodelet.  Go to [Nodelet
Settings] and enable the Free Nodelet if you
haven't already.
&lt;/p&gt;&lt;p&gt;
The main features are:
&lt;ul&gt;&lt;li&gt;No longer foul up square brackets in
JavaScript inside HTML comments.
&lt;/li&gt;&lt;li&gt;A way to get JavaScript square
brackets even outside of HTML comments.
&lt;/li&gt;&lt;li&gt;A way to "Add this node" similar to
what the "Personal Nodelet" has, but more
powerful.
&lt;/li&gt;&lt;li&gt;Simple templates for making
interesting links like "How AnonyMonk
sees this node" or "This node's author's
most-recent write-ups".
&lt;/li&gt;&lt;/ul&gt;
&lt;/p&gt;&lt;p&gt;
This enhancement should be considered
experimental, as it was a quick hack and a
much better design may be proposed after we
get more experience with it.  But I wanted to
actually deploy it so anyone could play with
it in order to encourage feedback on how to
improve it.  So, please try it out, but
realize that we might announce major changes
sooner or later that may break some of what
you write.
&lt;/p&gt;&lt;readmore&gt;&lt;p&gt;
All of the features (except the first) are
provided by a simple templating system that
uses &lt;code&gt;`&lt;/code&gt; (backtick) as the only
metacharacter.  This was chosen because it is
a character that is not useful in JavaScript
nor HTML.
&lt;/p&gt;&lt;p&gt;
Only in the Free Nodelet, &lt;code&gt;`id`&lt;/code&gt;
gets replaced with the current node's node_id.
&lt;code&gt;`title`&lt;/code&gt; gets replaced with the
current node's title.  If using the title
in HTML (almost always), use
&lt;code&gt;`title&amp;`&lt;/code&gt; instead to get the title
with &amp;, &lt;, &gt;, &amp;#91;, and &amp;#93; characters
escaped as HTML entities.  To use a title in a
URL, use &lt;code&gt;`title%`&lt;/code&gt; to have it
URL-escaped (using %xx).
&lt;/p&gt;&lt;p&gt;
The following items get expanded if put
between a pair of backticks (&lt;code&gt;`&lt;/code&gt;)
in the Free Nodelet:
&lt;ul&gt;&lt;li&gt;id - current node's ID
&lt;/li&gt;&lt;li&gt;title - current node's title
&lt;/li&gt;&lt;li&gt;author_id - current node's author's
user ID number
&lt;/li&gt;&lt;li&gt;author_name - current node's
author's name
&lt;/li&gt;&lt;li&gt;author_title - same as author_name
("title" of their home node)
&lt;/li&gt;&lt;li&gt;user_id - your ID (useful for writing
macros that another user can paste into their
nodelet)
&lt;/li&gt;&lt;li&gt;user_name - your monk name
&lt;/li&gt;&lt;li&gt;user_title - same as user_name
&lt;/li&gt;&lt;li&gt;_arg - the value of the CGI parameter
'_arg' or 'arg' ("arg" can be anything, but the
leading _ is required).
&lt;/li&gt;&lt;/ul&gt;
Each of the above can have a &amp;amp; or % on the
end (just before the closing backtick).  Other
items like root_id, root_title, sect_id, and
sect_title may be added in future.  You don't
need to use &amp;amp; nor % on *id items, since
they expand to just digits and digits don't
need to be escaped.
&lt;/p&gt;&lt;p&gt;
The above expansions happen before
&lt;code&gt;[...]&lt;/code&gt; links are processed, so you
can make a link like
&lt;code&gt;[id://`id`|Bookmark node `id`]&lt;/code&gt;.
&lt;/p&gt;&lt;p&gt;
The following substitutions are also made:
&lt;ul&gt;&lt;li&gt;&lt;code&gt;`[&lt;/code&gt; becomes &lt;code&gt;[&lt;/code&gt;
&lt;/li&gt;&lt;li&gt;&lt;code&gt;`]&lt;/code&gt; becomes &lt;code&gt;]&lt;/code&gt;
&lt;/li&gt;&lt;li&gt;&lt;code&gt;``&lt;/code&gt; becomes &lt;code&gt;`&lt;/code&gt;
&lt;/li&gt;&lt;li&gt;&lt;code&gt;```&lt;/code&gt; becomes &lt;code&gt;``&lt;/code&gt;
&lt;/li&gt;&lt;li&gt;&lt;code&gt;````&lt;/code&gt; becomes &lt;code&gt;```&lt;/code&gt;
&lt;/li&gt;&lt;li&gt;etc.
&lt;/li&gt;&lt;/ul&gt;
Note that &lt;code&gt;`[&lt;/code&gt; gets expanded in
such a way that the resulting &lt;code&gt;[&lt;/code&gt;
will not be processed as a PerlMonk's link
specification.  So the resulting
&lt;code&gt;[&lt;/code&gt; can be part of some JavaScript.
Inside of HTML comments, either
&lt;code&gt;`[&lt;/code&gt; or just &lt;code&gt;[&lt;/code&gt; can be
used.
&lt;/p&gt;&lt;p&gt;
Note that "HTML comments" at PerlMonks
simply start with "&lt;code&gt;&lt;!--&lt;/code&gt;" and simply
end with "&lt;code&gt;--&gt;&lt;/code&gt;".  In real HTML
comments, whitespace is allowed inside these
start/end sequences and occurrences of
"&lt;code&gt;--&lt;/code&gt;" inside the comments have
special meaning.  Since the Free Nodelet's
HTML is not filtered by PerlMonks, if you put
"&lt;code&gt;--&lt;/code&gt;" inside your HTML comments
there, you might "confuse" your browser, but
PerlMonks doesn't care about any appearances
of "&lt;code&gt;--&lt;/code&gt;" in your HTML comments when
it comes to deciding where to not process
&lt;code&gt;[...]&lt;/code&gt; as a link.
&lt;/p&gt;&lt;p&gt;
A &lt;code&gt;`_foo`&lt;/code&gt; gets expanded to whatever the _foo parameter was set to in the URL (or POST) used to fetch the page, such as via &lt;code&gt;;_foo=bar&lt;/code&gt;.  If the no "_foo" parameter exists, then the value of the "foo" parameter is used instead.  If not even a "foo" parameter exists, then the item is left as &lt;code&gt;`_foo`&lt;/code&gt;, just as is done with any unrecognized template-like item.
&lt;/p&gt;&lt;/readmore&gt;&lt;p&gt;
Below I'll include a couple of annoted
examples of how to use these features and even
the source code I used to implement the
features.  I look forward to your feedback.
&lt;/p&gt;

&lt;div class="pmsig"&gt;&lt;div class="pmsig-22609"&gt;&lt;p align="right"&gt;
- [tye]&lt;tt&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/tt&gt;
&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;</field>
</data>
</node>
