Creating new pages in Vanilla

As with most CMSs, it’s pretty tough getting into how Vanilla works, but it’s still my favorite by far, because of its simplicity to use and administrate.

It took me some time understanding how to create a brand new PHP page in Vanilla, as it’s not based on my favorite standard – having a header.php and a footer.php, the header also including all general functions and styles.

Say for example that you have a Vanilla forum but wants to include a new page about contact information, with the webmaster’s name and e-mail. With the system Vanilla uses, the first step is to create a new page (lets take for example contact.php).

[code=”php”””””]

include(”appg/settings.php”);
$Configuration[‘SELF_URL’] = ‘contact.php’;
include(”appg/init_vanilla.php”);

$Context->Session->Check($Context);

$Contact = $Context->ObjectFactory->CreateControl($Context, ”Contact”);

$Page->AddRenderControl($Head, $Configuration[‘CONTROL_POSITION_HEAD’]);
$Page->AddRenderControl($Menu, $Configuration[‘CONTROL_POSITION_MENU’]);
$Page->AddRenderControl($Panel, $Configuration[‘CONTROL_POSITION_PANEL’]);
$Page->AddRenderControl($Contact, $Configuration[”CONTROL_POSITION_BODY_ITEM”]);
$Page->AddRenderControl($Foot, $Configuration[‘CONTROL_POSITION_FOOT’]);
$Page->AddRenderControl($PageEnd, $Configuration[‘CONTROL_POSITION_PAGE_END’]);

$Page->FireEvents();

[/code]

The lines important here are number 2, 7 and 12, the rest can more or less be the same for any page. The two includes in the beginning call information needed to run the page (appg/settings.php and appg/init_vanilla.php). $Context->Session->Check($Context); checks who has the rights to view the page (as an admin of a Vanilla forum you can control if the forums are blocked to non-users, et cetera). The coming line gathers information on which control page to gather further information from. The easiest way is to have this page have the same name as the page itself, in this case Contact. Choosing this name will have the page collect classes from /library/Vanilla.Control.Contact.php, which we have yet to create:

[code=”php”””””]
class Contact extends Control {
function Render() {
include(ThemeFilePath($this->Context->Configuration, ‘contact.php’));
}
}
[/code]

This is really all that needs to be there for a simple page. This class calls the page /themes/contact.php, i.e. the page actually showing the HTML. Vanilla.Control.Contact.php, however, is the page where any PHP for more complex pages should go. If you’re uncertain on how it works, check some of the premade pages in Vanilla, for example Vanilla.Control.Categories.php.

On to the actual page, themes/contact.php, having the simplest code of all:

[code=”php”””””]
echo ”Howdihoo… the webmaster of this site is Blablabla, with the e-mail spam_me@spam.com.”;
[/code]

Easy enough. Let’s go through it once more:
/contact.php calls the actual site, saying it is controlled further by the page Vanilla.Control.Contact.php. It also says that it will use the traditional style with head, menu, panel, foot, and PageEnd, but with the central (between Panel and Foot) being the special ”Contact”, as presented in Vanilla.Control.Contact.php.
[code=”php”””””]

include(”appg/settings.php”);
$Configuration[‘SELF_URL’] = ‘contact.php’;
include(”appg/init_vanilla.php”);

$Context->Session->Check($Context);

$Contact = $Context->ObjectFactory->CreateControl($Context, ”Contact”);

$Page->AddRenderControl($Head, $Configuration[‘CONTROL_POSITION_HEAD’]);
$Page->AddRenderControl($Menu, $Configuration[‘CONTROL_POSITION_MENU’]);
$Page->AddRenderControl($Panel, $Configuration[‘CONTROL_POSITION_PANEL’]);
$Page->AddRenderControl($Contact, $Configuration[”CONTROL_POSITION_BODY_ITEM”]);
$Page->AddRenderControl($Foot, $Configuration[‘CONTROL_POSITION_FOOT’]);
$Page->AddRenderControl($PageEnd, $Configuration[‘CONTROL_POSITION_PAGE_END’]);

$Page->FireEvents();
[/code]

/library/Vanilla.Control.Contact.php, as already mentioned, presents the class Contact. What it does is in fact to include the page /themes/contact.php.

[code=”php”””””]
class Contact extends Control {
function Render() {
include(ThemeFilePath($this->Context->Configuration, ‘contact.php’));
}
}
[/code]

/themes/contact.php goes on to showcase the information to be shown visiting /contact.php, here very simply and without any complications, without advanced PHP or MySQL – that is to be run entirely from the Control page.
[code=”php”””””]
echo ”Howdihoo… the webmaster of this site is Blablabla, with the e-mail spam_me@spam.com.”;
[/code]

And you are done. Fix these pages, and if you are to visit /contact.php you will view the text Howdihoo… the webmaster of this site is Blablabla, with the e-mail spam_me@spam.com.. All of this is simple PHP, yet it took me quite some time to understand, being all new to these types of programming, and I’m sure others have the same problem. I am very new to writing guides, so if I’m being unclear please comment or e-mail me.

Related posts: