You are missing our premiere tool bar navigation system! Register and use it for FREE!

•  Home •  Downloads •  Gallery •  Your Account •  Forums • 
Readme First
- Readme First! -

Read and follow the rules, otherwise your posts will be closed
· Home
· Buy a Theme
· Advertising
· AvantGo
· Bookmarks
· Columbia
· Community
· Donations
· Downloads
· Feedback
· Forums
· Private Messages
· Search
· Statistics
· Stories Archive
· Submit News
· Surveys
· Theme Gallery
· Top
· Topics
· Your Account
Who's Online
There are currently, 230 guest(s) and 0 member(s) that are online.

You are Anonymous user. You can register for free by clicking here
How to create a Hello World block

20.5.1. How to create a Hello World block

Figure 20-4. Hello World block with Javascript.

Hello World block with Javascript.

We will start with a very simple block, one that just displays "Hello World". Once you get the idea, you will be able to construct any Javascript block for PHP-Nuke - they all follow the same rules.

We will keep the Javascript code in a separate file, say hello-world.php, in the PHP-Nuke includes directory. The includes directory is a natural place for it, because it also contains the javascript.php file (see Section 21.9.1). You can use the javascript.php file to store your own Javascript functions (as shown in Javascript in a PHP-Nuke block), but for this simple example, hello-world.php is more than enough. It contains only a few lines:

echo '
document.write("Hello World!");

Now, create a block, block-Hello_World.php, in the blocks folder that contains:

if (eregi("block-Hello_World.php",$_SERVER[PHP_SELF])) {
    Header("Location: index.php");
$content.="<center><script language=\"JavaScript\"

As you can see, block-Hello_World.php loads the hello-world.php from the includes folder as a Javascript code. hello-world.php, in turn, is executed and echoes the document.write command in the HTML file that is sent to the client's browser. When a the browser receives it (and has Javascript enabled), executes the code writing the "Hello World" message in the place it was called - in the Hello World block.

Using this technique, you can create blocks that are very rich in functionality - just echo their code with a PHP file and call that file as Javascript code from the block. See Section 20.5.3 for a non-trivial example.

Web site engine's code is Copyright © 2002 by PHP-Nuke. All Rights Reserved. PHP-Nuke is Free Software released under the GNU/GPL license.
Page Generation: 0.023 Seconds - 341 pages served in past 5 minutes. Nuke Cops Founded by Paul Laudanski (Zhen-Xjell)
:: FI Theme :: PHP-Nuke theme by coldblooded ( ::