Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Free Nodelet gets templating features (simple "add this" example)

by tye (Cardinal)
on May 08, 2005 at 07:36 UTC ( #454983=note: print w/ replies, xml ) Need Help??


in reply to Free Nodelet gets templating features

Here is a simple example of how to use (part of) your Free Nodelet to collect links to nodes, just like the Personal Nodelet can do. Go to Free Nodelet Settings and paste this into your Free Nodelet:

<ul> <!--todo-<li>[id://`id`] </li>--> </ul> [href://?node_id=`id`;op=_freer;at=todo|Add] "`title&`" above.

That HTML comment is a template for how to automatically add text to your Free Nodelet. The link at the bottom triggers this template to be expanded. If you go to node 22609, your Free Nodelet will show a 'Add "tye" above' link. Click it and you'll return to the same node but your Free Nodelet contents will be changed to:

<ul> <li>[id://22609] </li><!--todo-<li>[id://`id`] </li>--> </ul> [href://?node_id=`id`;op=_freer;at=todo|Add] "`title&`" above.

Let's break down how this works. {<!--} starts the HTML comment that contains the template. {todo-} as the first part of the comment gives the template its name, "todo". The {<li>[id://`id`]} and {</li>} are the body of the template, that is, the text that gets expanded and then inserted. {-->} closes the HTML comment and ends the template.

{[href://} starts a link back to PerlMonks. {?node_id=} lets us specify which node ID we want the link to take us to. The {`id`} gets replaced with the current node's ID so that the link takes us back to whatever node we were already at. {;op=_freer} means that clicking the link will run the '_freer' opcode which is what adds stuff to our Free Nodelet. {;at=todo} tells the _freer opcode the name of the template(s) we want expanded. {|Add]} finishes the link and says that the word "Add" is what we'll see and can click on to activate the link.

{"} and {" above.} are just text to be displayed in the nodelet. {`title&`} gets replaced with the title of the current node but with special HTML characters encoded as entities such that the title displays correctly. So what we see in the nodelet looks like:

Add "tye" above.

When we click that link, our browser goes to node 22609 (again) and the _freer opcode gets run. It finds the "todo" template and pulls out the body of it. It expands the {`id`}, replacing it with the current node's ID (22609), and then inserts the resulting expanded template body right before the template in our Free Nodelet's contents.

Then the node gets displayed to the browser with the newly updated Free Nodelet.

- tye        


Comment on Re: Free Nodelet gets templating features (simple "add this" example)
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://454983]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2014-08-21 14:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (136 votes), past polls