Scripts & HTML Fields in TOWeb

Page 23 of 27

The source code of your web pages can not be deleted or changed as TOWeb automatically generates or regenerates all your web pages. But you if you have some HTML code or scripts inside you can had them to your topics using TOWeb HTML Script Fields. Depending on your needs you may also Use a TOWeb Text Fields. Both types of scripts can have additional files.

You can insert or edit TOWeb fields when editing a paragraph using the field button but also create or manage all your scripts from the "Settings > HTML" step.

Script Fields

The example of %DATE% for the current date in JavaScript.
1) From the Fields' Editor create a new field by clicking on the Add the new field
2) Its default name is NEW_FIELD. Rename it to DATE
3) Set the Field Type to "HTML Script"
4) In the Script Field Content replace the default script with a copy/paste of the following lines of JavaScript source code :

var d = new Date(); ;
document.write(d.getMonth() + 1);
document.close() ;

5) Inside one of your topic add the following text :
The current date is : %DATE%
6) Generate and you should see, instead of %DATE% the current date displayed on your web page.

This simple script is just a small example of a JavaScript code displaying the current date. You may create or copy/paste more complex scripts containing HTML, Javascript, PHP, applets, etc.
If you need to use additional files in the topic for your script (like for instance images, videos or applets) you can add them to the list of additional files.

Another example : if you have any scripts in JavaScript that require to be called only when the page is fully loaded (eg for JQuery functions if you use this library) then you will need to declare a function named onTOWebPageLoaded in which you perform the copy / paste your code (the name of the finction is case sensitive). Below is a script example to change the link upon click on the logo of your site (made with a TOWeb version 5 or greater) to redirect to the Google site intead of going to your home page:

onTOWebPageLoaded function () {
$('#logo').click( function() { window.location = ""; return(false); } );
</ script>

PHP scripts
If you want to include a PHP script you need to use the Script Field as previously described but also have rename the topic file name with the file extension ".php". By default TOWeb gives to your topic an "Automatic" page name base on the topic title. To set or change a topic filename, just go to the "Topic settings" and inside the Search engine optimization type your filename with its filename extension before to press the check button aside.

Text Fields

The example of %ADDRESS%

1) From the Fields' Editor create a new field by clicking on Add the new field
2) Its default name is NEW_FIELD. Rename it to ADDRESS
3) Set the Field Type to Text
4) In the Text Field Content replace the default text ("Enter your field text here") by your full address. You may enter it on several lines like for instance :
911 Easy street
94043, Mountain View, CA
5) Click on the OK button and save your changes.

Now you have created a field ADDRESS containing your address. Every time you will need to use your address in a paragraph of your topics, simply type %ADDRESS% (with % at the beginning and at the name) or insert it where you want with a right-clicking and by selecting ADDRESS from the popup menu.
Then generate your website and this %ADDRESS% will be replace by the address you entered in all the web pages where you use it.

This example uses an email address but you may use text fields for any other purposes and text content you need (a copyright notice, the name of your company, a phone number, your slogan, etc). In fact any text information (short or long) that you may use at different places in your web site but do not want to update every time every where.

Predefined fields

If you want to place links pointing to the page of your site that contains your privacy policy, you can use the %TW-PRIVACY% field inside your texts.
If you use a introduction/agreement page on your site you can use the %TW-SITE-AGREEMENT% field.
In an e-Commerce site, the acceptance text of the sales conditions (modifiable from "Options> Languages > Translate predefined texts > Shopping cart management") can use the %TW-TOS% field to create a link to your Terms of Sales.