Hello World!

From Nephtali Documentation

Jump to: navigation, search

There are many ways to say hello in Nephtali.

Standard pipe

One way to code a "Hello World!" example is to add a pipe to a page that displays the output, as is displayed in the example below. The text and the current time are passed in through the dataset array.

Here's the markup, found in hello_world.php:

<!--pipe:hello-->
<!--view:default-->
<!--data-->
<p>{greeting}, it's {time}.</p>
<!--data-->
<!--view:default-->
<!--view:error-->
<p>Pardon our rudeness for not properly greeting you.</p>
<!--view:error-->
<!--pipe:hello-->

And, here's the code for the nephtali file hello_world.php found in the directory nsite:

n\pipe\register(
	$name = 'hello', 
	$function = function($markup)
	{
			return n\view\render($name = 'default', $markup, $rows = array(array('greeting' => 'Hello World!', 'time' => date(DATE_RFC822))));
	}
);

Output

When adding an entire pipe region to a page to display a values seems like overkill (perhaps adding dynamic text the the title of a page), Nephtali provides the capability to register singular outputs to the page. In the example below, the greeting is displayed through the use of registering Nephtali output.

All output is automatically escaped.

Here's the markup:

<p>{greeting}</p>

And, here's the code for the Nephtali file hello_world.php found in the directory nsite:

n\output\register('greeting', 'Hello World!');

Nregister.php

Nephtali also provides a way to add functionality to multiple pages through use of the nregister.php file. In the example below, the standard pipe version of the "Hello World!" example is added to every page within the cool_greeting directory.

Here's the markup, found in cool_greeting/index.php, cool_greeting/example.php, etc.:

<!--pipe:hello_again-->
<!--view:default-->
<!--data-->
<p>{greeting}, it's {time}.</p>
<!--data-->
<!--view:default-->
<!--view:error-->
<p>Pardon our rudeness for not properly greeting you.</p>
<!--view:error-->
<!--pipe:hello_again-->

And, here's the code for the nregister.php file:

if (n\url\current_path($paths = array('/cool_greeting')))
{
	n\pipe\register(
		$name = 'hello_again', 
		$function = function($markup)
		{
				return n\view\render($name = 'default', $markup, $rows = array(array('greeting' => 'Hello World!', 'time' => date(DATE_RFC822))));
		}
	);
}