Written 2010 by Will Johnson for Fast Forward Technologies Email Fast Forward Technologies at fft2001@aol.com or post your comments for public view far below. Creative Commons Attribution 3.0 License | Follow Fast Forward Technologies on Twitter! or use my Knol Public activity feed |
<-- Previous Lesson Google Gadgets: Lesson 1 "Hello World" | Next Lesson --> Google Gadgets: Lesson 3 "Acting on User Input" |
[Edit]
In this lesson, I show you how to write your second Google Gadget that will run inside a Knol: Setting User Preferences.
Google has decided that user settings should be called "User Preferences" so that's what we'll call it in this lesson, and that's the tag you have to use to set up these inputs.
So like before, first we set up our capsule
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="My Second Gadget" />
Then we establish that we're going to use a user preference.
<UserPref
name="myName"
display_name="First User Pref"
default_value="Bill Jones"
required="false" />
[Edit]
And here's how you use it
<Content type="html">
<![CDATA[
Hello "__UP_myName__"
]]>
</Content>
The "__" at the beginning and ending of the variable name UP_myName are required encapsulations so that the gadget knows that this thing which is encapsulated here, is in fact, a variable.
Then we close the capsule
</Module>
[Edit]
Now we run it. (Now before you get all up-in-my-face, read the next paragraph to explain why you're seeing an odd result here.)
My Second Gadget
[Edit]
Now I'll insert a new copy of the same gadget with a slight change. Here I'm testing two things. One, whether when Knol loads the code it makes a copy of it, and uses its own stored version for all future time. And second, testing the code change which shows you can use the same preference again, and what happens if you forget the __UP
<Content type="html">
<![CDATA[
Hello "__UP_myName__"
Hello "__UP_myName__"
Hello "_myName__"
]]>
</Content>
My Second Gadget
[Edit]
Read more about User Preferences at code.google.com
Evidently Knol still has a few bugs. Sometimes the results of my Gadgets appear in the Advertising space on the far right. Sometimes the results appear in the Advertising space at the far bottom!
And as we've discovered, Knol seems to delay the reading of the Gadget code after you've made a change. The first version of my Gadget still displayed the old result, while the second version, right here on the same page, displayed, at the exact same moment, the new results. After some minutes, or perhaps another edit and save, suddenly both are displaying the same result now. Not sure if that's a bug or a feature!
<-- Previous Lesson Google Gadgets: Lesson 1 "Hello World" | Next Lesson --> Google Gadgets: Lesson 3 "Acting on User Input" |