Object oriented Smart Templates Engine
Smart Template Engine
Installation / Tips Database Engine Interface Smart Parser Engine
Step by step installation
Database (DE) mode FAQ
Templates (TE) mode FAQ
Examples
Tips
Admin interface
Actions Editor
Jump Editor
Mailing Editor
Key Fields
Syntax
How to use TE
How to use DE

(*) DE - Database Engine
(*) TE - Template Engine
         Syntax

Smart Parser tags:

PARSE__
SET__
ARRAY__
BBCODES__

FORM__
TEMPLATE__

SUBMIT__
RADIO__
PAGE__
PRINT__


top
[PARSE__GET|PAST name=define]

parse some GET or POST variable with delimeters into others variables.
Example: you call the script and setup mod_rewrite rule to redirect
http://yourdomain.com/alex/archive/1/ to your script index.php?cat='alex/archive/1'

Include this line in your file
[PARSE__GET cat = {author}/{alias}/{page}] so you it will be possible to parse GET vars and use values in VAR(GET.field) directive : [CASE VAR(GET.author)=="John"] or output the value of each field - {author}, {alias}, {page} and so on.

top


[SET__name]
similar to php "define" function, it means that SP.TE set SET name to its body. Can be called as a $name in FORM__ and TEMPLATE__ tags. If called in name
[FORM__$name]
SET name becomes template name. If some lexem match, template lexem replaces SET
[FORM__$name ^MySQL : SELECT * FROM table ^WHERE : $where_set ]

top
[ARRAY__name =(define)]

SmartParser Array. It is required to be in php array format, the same as array(). This function can be associative, multi-dimensional. This tag is used in templates (see below)
[ARRAY__SmallStatus=("0"=>"","1"=>"<b><span class='t1_b'>&nbsp;Active&nbsp;</span></b>","2"=>"<b><span class='t1_c'>&nbsp;Suspended&nbsp;</span></b>")]
...
[TEMPLATE__$AllAuthors]
...
{Status [$status] }

top

[BBCODES __

^Name = define

]

Users' BB CODES. In define description it is possible to use {option} and {param}

Example:

[BBCODES __ ^CLASS : <span class ='{option}'>{param}</span>]

Then you can put this structure into textarea fields, stored in MySQL table and then SP will use it when call {TXT__ structure in TEMPLATES
[CLASS=option] param [/CLASS] -> <span class='option'>param</span>

top
[FORM__name
^ON               = define
^NOCREATE = define
^GO               = define
^MYSQL       = define
^WHERE       = define
^TABLE        = define
^ID               = define
]

[END__FORM__name]

Everything except name is not obligatory.

^ON
checking on the presence of specified value in POST array. If absent - then this form is cut out. It is possible to write the name of the form created by SP (SmartParser) under the ^FORM construction (see below).

^NOCREATE
Do not create < form …> construction. If not specified, SP prints out relative
<form name='name' method='post' action='GO define'>
<input type='hidden' name='name' value='1'>

Hidden input is used for processing of data manipulation from this form to the MySQL table.

^GO
Name of the "action" file. < form … action =''>.
If omitted, SP uses PHP value: SERVER [" REQUEST _ URI "]

^MYSQL
MySQL query for quering data for TEMPLATES or for filling FORM's fields values.
VAR structure - "VAR ( varname )" can also be used. (see below)

^WHERE
Part of MySQL expression. "VAR(varname)" construction can also be used (see below).

^TABLE
Name of the table corresponding to given form. This structure is required if the form contains IMG__ tag (see below).

^ID
Key field name. It is required if form contains IMG__ tag (see below).

 

top

[TEMPLATE__ name

^MYSQL = define
^WHERE = define
^IF          = define
^CELL      = define (updated!)
^CODE    = define
^TABLE   = define
^ID          = define
^LIMIT    = define
^UPDATE   = define (new!)
^CASE       = define (new!)
^CACHED (new!)
]

Since it is "Template Engine" tag , then, in the current version, there can only be FT tags inside.

You can use this SET__ structure to describe your templates:

    Example:
In this example we request two databases: "cd" and "urls" and then show all CD's type and titles, but if the type of CD ='mp3', we will show 10 related URLs.

 

<? include(“./sp/sp_start.php”); ?>

[SET__CDs
^MYSQL : SELECT * FROM cd
]
[SET__
MyTemplate
^MYSQL : SELECT * FROM urls
^WHERE : status = 'Active' and cdid=VAR(CDs.ID) LIMIT 10
^CELL : CELL(2)
^CASE: VAR(CDs.type)=='mp3'
]

<html>
<body>

[TEMPLATE__$CDs]

{ID} {type} {title}

[TEMPLATE__
$MyTemplate]

ID: {cdid}, URL: {url}

[END__TEMPLATE__MyTemplate]
[END__TEMPLATE__CDs]
</body>
</html>


<? include(“./sp/sp_end.php”); ?>



 

<? include(“./sp/sp_start.php”); ?>

[SET__
FindCurrentCategory
^MYSQL : SELECT ID,alias,title,type FROM sp_news
^WHERE : type = 'Category' AND status = 'Active' LIMIT 5
]
[SET__FindStaticNews
^MYSQL = SELECT *, UNIX_TIMESTAMP(LogTS) AS mytime FROM sp_news
^WHERE type = 'Post' AND category = VAR(FindCurrentCategory.ID) ORDER By LogTS LIMIT 20
^TABLE = sp_news
^ID = ID
]

<html>
<body>

[TEMPLATE__$FindCurrentCategory]

Category ID: {ID}, Category: {title}

my text

[TEMPLATE__$FindStaticNews]

Article ID: {ID}
Author: {author} - Date: {mydate} - Article title: {title} <br> {text} <br>

[END__TEMPLATE__FindStaticNews]

my text

[END__TEMPLATE__FindCurrentCategory]

my text

</body>
</html>


<? include(“./sp/sp_end.php”); ?>

^MYSQL
MySQL query for data output. It is possible to use "VAR(varname)" construction inside,
where "varname" is [ POST.,GET.,TemplateName.] Name [=default value ]

  • Name - sSearch Name in php array $_POST, if not found – in the current record of current template table, otherwise - '' and error
  • POST.Name - Search Name in php array $_POST, otherwise returns "" ( empty ) value and error.
  • GET.Name - Search Name in php array $_GET , if not found in php array $_POST , otherwise returns "" ( empty ) value and error.
  • TemplateName.Name - Search Name in the last processed template's record
    TemplateName ($ row _ data [ TemplateName ][ Name ]) , if not found – in the PHP array $_POST , otherwise returns"" ( empty value ) and error.
  • default value – if Name was not found, returns default value instead of an error. If the returning value is not a number, returns result in quotation marks.

^WHERE - a part of MySQL query, VAR(varname) can also be used

^IF
checking on data output. Use like in PHP expressions ( ==, > etc.). VAR(varname) structure can also be used (see above)

^CELL
is used for so called “inside” output. Smart Parser duplicates block's content inside the template body.

<!--##
comment -->

<!--endd-->

if indicated CELL : N - blocks are repeated N times, regardless of the number of records.

if indicated CEIL : CELL ( N ) - blocks are repeated N times, script outputs parsing results for this template, CELL blocks are repeated again N times, template is put out, and so on. It means that template body will be put out N times

^CODE name.php
The name of php file, which will be called every time after receiving data from the table but before the template output. Values from the table are located in $row_data array as $row_data[TemplateName][FieldName]

CODE file can be used for data processing by changing $row_data[TemplateName][FieldName] or for setting“new” fields, e.g.

$row_data[TemplateName][GeneratedFieldName] = $row_data[TemplateName][FieldName] + 10;

In template you can call this field as {GeneratedFieldName}

^TABLE name
The name of the table, corresponding to current form. It is required if form or template contains {IMG__}, {CHECK__DELETE}, ^UPDATE tags (see below).

^ID fieldname
key field name. It is required if form or template contains {IMG__}, {CHECK__DELETE}, ^UPDATE tags (see below).

^LIMIT number
Page output parameter means how many records to show on one page. It is used together with
PREV __, NEXT __, FIRST __, LAST __, PAGES __

^CACHED
Use this tag if you cann the same template 2-3-N times on the page and the look of output is the same for all template's calls. It will save a time on MySQL queries.


There are following structures for output of table record values inside the template body:

{fieldname} – value of the the database field "fieldname". Use this tag {} to output fields values.

{#} - output current number of a record in the query.

{ENC __ fieldname} – php function (urlencode) result ( fieldname )

{DATE__ fieldname (format=define)} – php function date. Result - date(format,fieldname)

{CHK__ fieldname} – if { fieldname }==0, output No , otherwise - Yes

{TXT__ fieldname[(start=val, end=val [,symbol [ = 'character'] ] [,bbcodes] ) ] }
<textarea> text fields output with replacing /n for <br>.

    Example: {TXT__mytext (start=1000,end=2000, symbol = ';', bbcodes) }


If start and end are present, then the section from start to end position is chosen
If start is indicated, end is omitted – then end is considered as last position
If end is indicated, start is omitted – then start is considered as first position
If symbol = ' character ' is indicated - then' character ' is a splitter.
If symbol indicated without the value, then 'charaster' = ‘.' (dot)

If bbcodes is included into the set – text is looking for bbcodes presence (see below) and parse this text accordingly.

{IMG__ fieldname( x=val, y=val, color=44555, link=val )}
Picture output. It works with SP.DE table structure, i.e. for the tables created by Fsave (Database Engine Interface) only. It is required to include ^Table and ^ID structures into the ^TEMPLATE SET.

If dimensions are set it will be the thumbnail of the picture with predefined size (x,y)

x – horizontal size

y – vertical size

color - color in HEX format,

link - a link for image. VAR() can also be used

    Example:
{IMG__imagefield} - unchanged image

{IMG__imagefield(x=100,y=100,bbcodes)} - will try to show the image the best possible way,
will use X OR Y to create a thumbnail

{IMG__imagefield(x=100,y=200,color=333333,bbcodes)} - willl use X OR Y to create a thumbnail, but image will be 100x200 as unused part will be filled by color (#333333)

{RADIO__ fieldname}
FP will replace this with <input type='RADIO' name=' fieldname ' value='{fieldname}'>

{CHECK__ fieldname}
FP will replace this with <input type='checkbox' name=' fieldname[] ' value='{fieldname}'>

{SUBMIT__ fieldname}
- this is not the same as [SUBMIT__name]
FP will replace this with <input type='SUBMIT' name=' fieldname ' value='{fieldname}'>

*** where {fieldname} is a value of "fieldname" field.

{CHECK __ DELETE} - SP.DE will show a checkbox for deleting records from the table, this structure will be replaced with <input type='checkbox' name='TemplateName__delete[]' value='{ID}'>

SP.DE is checking the availability of similar values in $POST and make them deleted.
Note: if checkbox is not marked, POST array is empty.

{SPArrayName[$fieldname]} - use it to call a value from SP array.
Multy-dimensions is allowed, i.e. SPArrayName [‘ table '][ $ field 1 ][$ field 2 ]

 

top

[CASE__name (condition) ]

… body …

[__ELSE__name ]

…else body …

[ENDCASE__name]

... test ...

[CASE__name (condition) ]

… body …

[ENDCASE__name]

Condition should be conditional expression of php format ( ==, > etc.), VAR(varname) structure can also be used ( see above)

If expression is “correct” - …body… is put/brought out, if not – nothing or, if available, __ELSE__ block content.

top

[SUBMIT__name [=value]]

SP outputs <input type='submit' name='name' value='value'> . If value is omitted, name is put as a value.

top

[RADIO__name [=value]]

SP outputs <input type='radio' name='name' value='value'> . If value is omitted, name is put as a value.

If a structure "Limit" is indicated in template description, then template records are output by pages in Limit quantity.

top

[PAGE__FIRST]

<a href ...> link to the first page

[PAGE__PREV]

<a href ...> link to the previous page

[PAGE__PAGES]

maximum number of pages to output

[PAGE__NEXT]

<a href ...> link to the next page

[PAGE__LAST]

<a href ...> link to the last page

top

[PRINT__TIME]

 1997-2004 © Copyright "H-2.com"    Developed by H-2.com