Basic Concepts
All data in Ariadne is contained in objects. These objects form a tree like structure, just as a normal file system. Every object has a type, or 'class'. This class defines the behaviour and the layout of that object. The class defines which data an object of that class should contain and it defines a standard set of templates on that object, the class templates.
To build a website, you create a structure of objects and a set of templates. These templates are then combined with the content from the objects by Ariadne to form your website:
The default class template is 'view.html'. That is the template that you are looking at right now... but this template can be overridden for parts of the data tree, like it is here, by an object template. This allows you to change how an objects looks per directory. You can compare the view.html template to an index.html file on a normal webserver. When you do not put an index.html file in a directory, the webserver will display its own default view of a directory when you request that directory in the URL. Only when you override that view by placing an index.html file there, can you define a new layout and content. The same thing can be done in Ariadne with a view.html object template.
You can create your own object template via the 'layout' tab on the toolbar. (edit > layout > templates)
Go to the layout view of an object (preferably a directory) and click on 'new'.
You can now enter a new object template. At the top of the page is a pull down menu with all object classes (or types) and a text field named 'Template'. Ignore the language and 'default' checkbox for now.
You can now enter some html in the large text entry field. e.g.:
<html> <head><title>My template</title></head> <body bgcolor="white"> <h1>This is my template</h1> </body> </html>
Now type in the template name in the 'Template' field, e.g. 'my.html' and click on save. You will now see the templates overview page again, with your new template listed. If you didn't change the type it should display the type of the current object with your template name.
Now open a new browser window with the current object and type in your template name after its path, e.g.
http://www.example.com/ariadne/loader.php/my.html
You have now succesfully made your first object template, but it doesn't really do much yet. Return to the templates view and click on 'my.html'. You can now edit your own template again. Let's try to add some data from the object, e.g. the name, in your template.
<html> <head> <title><pinp> echo $nlsdata->name; </pinp></title> </head> <body bgcolor="white"> <h1>This is <pinp> echo $nlsdata->name; </pinp></h1> </body> </html>
Now reload the template in the seperate browser window and you will see the name of the object embedded in the template. If you edit the object and change the name, the name will be changed in your template also.
Make sure you always end each pinp command with a ';' Also, each pinp code block should start with <pinp> and end with </pinp> Otherwise the code won't be interpreted properly and you'll get an error message.
All objects save their data in the special variable $data
. A
basic object (pobject
) only has $nlsdata->name
and
$data->value
. Both are strings. But a Directory
(pdir
) and a Page (ppage
) have
$nlsdata->name
, $nlsdata->summary
and
$nlsdata->page
. Every object class at least has
$nlsdata->name
defined. More information about each object class
can be found in the Class reference. The
following variables are always available in each object:
$path full path to the current object $parent full path to the current object's parent $id unique identifier (number) for this object $type class name of the current object (e.g. 'pobject','pdir',..)
You can do a lot more than simply displaying the name or summary of an
object. There are some functions you can use to call templates in other objects,
e.g. you can list al the children of an object via the function
ls()
:
<html> <head> <title><pinp> echo $nlsdata->name; </pinp></title> </head> <body bgcolor="white"> <h1>This is <pinp> echo $nlsdata->name; </pinp></h1> <p> <pinp> ls("show.phtml"); </pinp> </body> </html>
You will now see all the children of this object too. The function 'ls' lists all the objects directly below the current one. If there are no objects, create a few.
For PHP programmers, it is important to notice that instead of doing a database query and then looping through the results, as you would do in a normal PHP program, all the looping in Ariadne is done 'invisibly'. The ls() function is actually a method of the object that runs this template. It knows which objects are its children, and politely asks each one in turn to display itself using the 'show.phtml' template.
The argument given to ls ("show.phtml
") tells it which template
to use to display each object it finds. In this case it is a predefined template
( a class template ). As you see the template ends in the extension ".phtml",
this means that it is a protected class template, you can't redefine it with an
object template.
Now go back to the templates screen and click on new and enter the following template:
<a href="<pinp> echo make_url(); </pinp>"><pinp> echo $nlsdata->name; </pinp></a><BR>
In the Type selectbox select type 'Object' and save this template as "show.html". Make sure you leave 'Default' checked! Now go edit 'my.html' again and change 'show.phtml' to 'show.html' in the call to ls:
<pinp> ls("show.html"); </pinp>
Now you will also see all the children, but instead of the class template 'show.phtml', your own object template 'show.html' is called for each child. This is what the 'default' checkbox is for. If you defined 'show.html' as not default, the children objects wouldn't have known any template called 'show.html', and would have displayed an error message instead. Try it.
When you uncheck the default checkbox and click 'Save', you will see your
template in the list with a strange icon () in front of it. This is the sign that that
template is defined 'local' or 'not default'. The effect is that that template
is unavailable on any other object, except the current one.
There are a lot more functions like 'ls' you can use to access objects in the Ariadne system, following are the functions that are always available:
call($template, $args); get($path, $template, $args); ls($template, $args); find($criteria, $template, $args); parents($template, $args); exists($path); getvar($name); putvar($name, $value);
Besides these there are a lot more utility functions like
'make_url()
'. For a complete list of Ariadne functions, go to the
class reference,
specifically the function reference of
pobject. And while PINP Is Not PHP, a lot of PHP functions will
work in a PINP script (or object template). A full list of general functions
available is in the PINP reference