Business templates

ASP.NET, PHP, Tutorials

Business Templates are pre-built mini-projects that can quickly add some specific functionality to your projects like Calendar or ToDo List. This article will teach you how to become a Business Template guru.

Btw, here are top three templates of all times:

Calendar template DocManager template Quiz template
Document management template Quiz template

Installing templates and creating projects

Our software comes with ten free templates that are already pre-installed. Additional Templates that you purchase need to be installed to <Directory where ASPRunnerPro or PHPRunner or ASPRunner.NET installed>\templates\business. Once installed you can run the software and create a new project from one of the installed templates.

You will be prompted to select a database and after all required tables and code will be created and you can build and use your project right away.

Adding templates to existing projects

This is probably the most complicated topic. Imagine the situation, when both your project and the template you adding have their own login table. Our software will offer you to choose, what login table (Security Template) is to use but both options have their disadvantages. We’ll show you how to add the template with its own login table to the project.

In this example, we will be adding DocManager template to the existing project.

1. Add DocManager template to project. Keep the existing project login table.

2. Start another instance of the software and create a new project using the same DocManager template. When prompted choose ‘Use existing tables’ option.

3. Proceed to the doc_users table, see what fields are there besides username and password fields. In our case those additional fields are email, usertype and name. Add the same fields to the login table in your main project. If such a field already exists then don’t add it.

4. Proceed to DocMamager project Global events like AfterAppInit, AfterSuccessfulLofin, AfterSuccessfulRegistration etc, copy the code there and add it to respective events of your own project. Normally you can add new code to the beginning of the event, unless it contains a redirect to another page. The code with redirect should be placed to the end of the existing event code.

Now you can close the DocManager project (no need to save it), build your original project, and test it. In newer versions of our software we will perform most of these steps automatically.

You can also add more than one template to the project using the same approach.

Upgrading templates

To upgrade a template, remove the template tables from the project on the Datasource tables screen, then add the template to the project again.

Note: to avoid overwriting the existing tables with the template ones, all template tables and files have a unique prefix. For example, the tables of the ‘Cars’ project template have the ‘cars’ prefix.

1. Remove the tables of that template from the project by deselecting them on the left panel.
2. Add the template back to the project by clicking the Project button and selecting Add/manage business templates.

Removing the template from the project

1. Remove template tables from the project, similar to what is described in Upgrading templates.

2. Remove template specific code from common events like AfterAppInit, AfterSuccessfulLogin event etc. Normally template specific code is wrapped by respective comments to make it easier for you to locate it.

For instance, here is the code that Calendar control adds to AfterAppInit event.

// Calendar template - begin

global $calendarSettings;
global $calendarDatasourceTableNames;
$calendarSettings = array();
$calendarDatasourceTableNames = array();
			
include_once(getabspath("include/calendar_functions.php"));
include_once(getabspath("include/calendar_holidays.php"));
add_daysname();
$calendarDatasourceTableNames["calcalendar"] = "calcalendar";
calendar_init();
checkCalendarSettings();

// Calendar template - end

Using your own tables

All templates come with their own tables and all the code in the events expected certain field names in these tables. That being said, making templates use data from your own table is not an easy task but some templates, like Calendar, support this kind of flexibility. We are also working on making this kind of functionality available in other templates.

Other integration options

Another integration possibility, you can create records in template tables automatically. For instance, after you create a work order you want to see it’s start date on the Calendar. Here is the sample code that you can add to event AfterAdd event of work orders table.

$data = array();
$data["DateField"] = $values["start_time"];
$data["Subject"]  = $values["notes"];
$data["Category"]  = "orders";
DB::Insert("calcalendar", $data );

Once you do this you can see your work order in the Calendar.

Extensibility

Even though templates come with a lot of existing functionality each project is different and people want to customize it according to their needs. This is why we offer a bunch of custom hooks in newer templates. For instance, in ToDo List Template you can easily change the single card view or send an email after the new card is created. Make sure to check each individual template documentation to see al extensibility and customization options.

function prepareCard($data) {
// this function is executed when we prepare text to  be shown on the card
// $data - an array with card values from tocards table
// return value: text to show on the card
    $value=$data["cardname"];
		if ($data["duedate"]) {
				$value.="
Due date: ".date("M j, Y", strtotime($data["duedate"])); } return $value; } function afterCardCreated($cardid){ // executed after card is created // $cardid - id of the card (from todocards table) $data = array(); $keyvalues = array(); $data["cardcolor"] = DBLookup("select id from todocategories where name='Errands'"); $data["priority"] = "medium"; $keyvalues["id"] = $cardid; DB::Update("todocards", $data, $keyvalues ); }

Using templates to merge projects

If you need to merge two projects together you can save one of them ‘as template’ and then add this template to the second project.

What templates are available

Our software comes with ten free templates. There are also thirteen premium templates that can be purchased separately.

Free templates
Cars
Jobs
Sporting
Vacations
Knowledge Base
PayPal
Classifieds
Events
News
Real Estate

Premium templates
Calendar
Invoice
DocManager
Forum
Resource Calendar
PDFForms
ToDo List
Survey
Quiz
Shopping Cart
Members
MassMailer
EmailReader

If you have questions about templates that are not covered in this article feel free to post in comments.

Leave a Reply

Your email address will not be published. Required fields are marked *