English فارسی Suomi
Français Nederlands Translate

Campsite 3.4

Campsite: TemplateLanguageVersion3

What's New In the Template Language In Version 3.0

In this chapter:
  • Template Engine Structure
  • Syntax Changes

 

Template Engine Structure

The Campsite extension to Smarty will initialize objects that are specific to Campsite: article, section, issue, image etc. These objects are instantiated from meta classes (e.g. MetaArticle, MetaSection etc.) and use method call overloading for allowing the web designer to access object properties (see: http://www.php.net/manual/en/language.oop5.overloading.php). This way we won't expose the core Article, Section etc. objects to the web designer so he/she won't be able to play with the database. These meta classes will only implement the _ _get() method, _ _set() will be empty or throw an error. Meta classes will use the existing classes (Publication, Issue, Section etc.) to retrieve the data. Meta classes will also implement the method "defined()" that returns true if the object instantiated from the class was actually initialized.

The template engine will initialize the $campsite object, which stores the whole Campsite environment (meaning all template parameters, objects, properties etc.). The $campsite object has the following read/write properties:

  • language
  • publication - holds data for the current publication
  • issue
  • section
  • article
  • topic
  • url
  • defaultLanguage
  • defaultPublication - holds data for the publication defined at the beginning of the template
  • defaultIssue
  • defaultSection
  • defaultArticle
  • defaultTopic
  • defaultUrl
  • currentList
  • user
  • user->subscription
  • search

and the following read-only properties:

  • current_issues_list
  • current_sections_list
  • current_articles_list
  • current_article_attachments_list
  • current_article_comments_list
  • current_article_images_list
  • current_article_topics_list
  • current_article_audio_attachments_list
  • current_search_results_list
  • current_subtopics_list
  • current_subtitles_list
  • current_list

Syntax Changes

Conventions

  • #element# will be replaced by the corresponding language element based on the semanting of 'element' word (e.g. #statement#: List, Article etc., #value#: a certain string, integer or other type value)
  • [element] means the element is optional
  • <!** > are the old begin/end tags
  • {{ }} are the new begin/end tags
  • if #element# is a predefined identifier (e.g. #statement#, #attribute#) then in the new syntax it will converted always to the following style: all letters are lower case (e.g. ARTICLE -> article, article -> article, Article -> article); words are separated by underscore (e.g.: ArticleComment? -> article_comment) (see "Article comment" in "Template Objects" chapter)
  • [#element#]+ means the element can occur 0 to multiple times
  • \[#element#\] is replaced by [#element#], like accessing array elements by keys: $article\[#element#\] -> $article[#element#]

Environment Manipulating Statements

Set/Unset Statements

Old syntax:

1. <!** #statement# #attribute# #value#>⁞
2. <!** #statement# default>
3. <!** #statement# current>
4. <!** #statement# off>

New syntax:

1. {{ set_#statement# #attribute#="#value#" }}
2. {{ set_default_#statement# }}
3. {{ set_current_#statement# }}
4. {{ unset_#statement# }}

Local Statement

Old syntax:

<!** Local>
<!** EndLocal>

New syntax:

{{ local }}
{{ /local }}

Include Statement

We will use the include statement implemented in Smarty.

Exceptions

Old syntax:

1. <!** HTMLEncoding on>
2. <!** HTMLEncoding off>

New syntax:

1. {{ enable_html_encoding }}
2. {{ disable_html_encoding }}

Examples

<!** Article number 125>

changes to:

{{ set_article number="125" }}
<!** Article off>

changes to:

{{ unset_article }}

List Statements

Old syntax:

<!** List [length #value#] [columns #value#] #statement# [#contraints#]
          [order #order_constraints#]>
<!** ForEmptyList>
<!** EndList>

New syntax:

{{ list_#statement#s [name="#value#"] [length="#value#"] [columns="#value#"]
                     [constraints="#constraints#"] [order="#order_constraints#"] }}
{{ if $currentList->empty }}
{{ /if }}
{{ /list_#statement#s }}

Constraints will require a 'Constraint Parser'. The Constraint Parser has the following requirements:

 * constraints can contain variables
 * constraints can contain "&&"(AND) and "||" (OR)
 * constraints can contain parenthesis

Exceptions

Old syntax:

1. <!** List [length #value#] [columns #value#] ArticleAttachment ForCurrentLanguage>
2. <!** List [length #value#] [columns #value#] ArticleAttachment ForAllLanguages>
3. <!** List [length #value#] [columns #value#] Subtitle>

New syntax:

1. {{ list_article_attachments [name="#name#"] [length="#value#"]
                               [columns="#value#"] language="current" }}
2. {{ list_article_attachments [name="#name#"] [length="#value#"]
                               [columns="#value#"] language="all" }}
3. {{ list_subtitles [name="#name#"] [length="#value#"] [columns="#value#"]
                     [articleType="#value#"] field="#value#" }}

In the exception example 3 articleType and field attributes are read from "With" statement from the old template language.

If Statements

General Syntax

Old syntax:

1. <!** If [not] #statement# >
2. <!** If [not] #statement# #attribute# >
3. <!** If [not] #statement# #attribute# #value# >
4. <!** If [not] #statement# #attribute# #value# [#value#]+ >
5. <!** If [not] #statement# #attribute# #operator# #value# >
6. <!** If [not] #statement# #article_type# #attribute# #operator# #value# >

New syntax:

1. {{ if [!] $#statement# }}
2. {{ if [!] $#statement#->#attribute# }}
3. {{ if [!] ($#statement#->#attribute# == "#value#") }}
4. {{ if [!] ($#statement#->#attribute# == "#value#"
              [and $#statement#->#attribute# == "#value#"]+ ) }}
5. {{ if [!] ($#statement#->#attribute# #smarty_corresponding_operator# "#value#") }}
6. {{ if [!] ($#statement#->type->#article_type#->#attribute#
              #smarty_corresponding_operator# "#value#") }}

Exceptions

Old syntax:

1. <!** If [not] Allowed>
2. <!** If [not] Article upload_date #operator# #value# >
3. <!** If [not] Article has_keyword #value# >
4. <!** If [not] Article translated_to #value# >
5. <!** If [not] CurrentSubtitle >
6. <!** If [not] Image #value# >
7. <!** If [not] Login #attribute# >
8. <!** If [not] NextItems >
9. <!** If [not] PreviousItems >
10. <!** If [not] NextSubtitles >
11. <!** If [not] PrevSubtitles >
12. <!** If [not] Search #attribute# >
13. <!** If [not] User #attribute# >
14. <!** If [not] Subtitle number #operator# #value# >

New syntax:

1. {{ if [!] $article->content_accessible }}
2. {{ if [!] $article->creation_date #smarty_corresponding_operator# "#value#" }}
3. {{ if [!] $article->keyword == "#value#" }}
4. {{ if [!] $article->translationLang == "#value#" }}
5. {{ if [!] $article->subtitle->is_current }}
6. {{ if [!] $article->image_number == "#value#" }}
7. {{ if [!] $user->login_#attribute# }}
8. {{ if [!] $current_list->length gt $current_list->last_element->index }}
9. {{ if [!] $current_list->first_element->index gt 1 }}
10. {{ if [!] $current_list->length gt $current_list->last_element->index }}
11. {{ if [!] $current_list->first_element->index gt 1 }}
12. {{ if [!] $article->search#attribute# }}
13. {{ if [!] $user->subscription_#attribute# }}
14. {{ if [!] $article->subtitle->number #smarty_corresponding_operator# "#value#" }}

With Statement

This statement is not used anymore, see example 3 from "List" exceptions.

URL Statements

Old syntax:

<!** #statement# [#option#]+ >

New syntax:

{{ #statement# [options="[#option#]+"] }}

Where #statement# can be one of the following: URIPath, URLParameters, URI, URL, FormParameters?.

Date Statement

Old syntax:

1. <!** Date #attribute# >
2. <!** Date #date_format# >

New syntax:

1. {{ $smarty.now|camp_date_format:"#corresponding_smarty_date_part#" }}
2. {{ $smarty.now|camp_date_format:"#date_format#" }}

Print Statements

Old syntax:

1. <!** Print #statement# #attribute# >
2. <!** Print Article [#article_type#] #attribute# >
3. <!** Print #statement# #attribute# #date_format# >

New syntax:

1. {{ $#statement#->#attribute# }}
2. {{ $article->[type->#article_type#->]#attribute# }}
3. {{ $#statement#->#attribute#|camp_date_format:"#date_format#" }}

Exceptions

1. <!** Print ArticleAttachment #attribute# >
2. <!** Print ArticleComment #attribute# >
3. <!** Print ArticleComment readerEmailObfuscated >
4. <!** Print ArticleComment readerEmailPreviewObfuscated >
5. <!** Print Subtitle name >
6. <!** Print Image [#imageNumber#] #attribute# [#date_format#] >
7. <!** Print List #attribute# >
8. <!** Print Login error >
9. <!** Print Search #attribute# >
10. <!** Print Subscription #attribute# [#date_format#] >
1. {{ $article->attachment->#attribute# }}
2. {{ $article->comment->#attribute# }}
3. {{ $article->comment->reader_email|camp_obfuscate }}
4. {{ $article->comment->reader_email_preview|camp_obfuscate }}
5. {{ $article->subtitle->name }}
6. {{ $article->image[\[#imageNumber#\]]->#attribute#[|camp_date_format:"#date_format#"] }}
7. {{ $current_list->#attribute# }}
8. {{ $user->login->error_message }}
9. {{ $article->search->#attribute# }}
10. {{ $user->subscription->#attribute#[|camp_date_format:"#date_format#"] }}

{{ $article->title }}
{{ $article->type->data->intro }}

Form Statements

Old syntax:

1. <!** #statement# #template_name# #submit_button_name# >
2. <!** ArticleCommentForm #template_name# #submit_button_name# [#preview_button_name#] >
3. <!** Subscription #subscription_type# #template_name# #submit_button_name#
                     [#total_field_name# #evaluate_button_name#] >

New syntax:

1. {{ #statement#_form template="#template_name#" submit_button="#submit_button_name#" }}
2. {{ article_comment_form template="#template_name#" submit_button="#submit_button_name#"
                           [preview_button="#preview_button_name#"] }}
3. {{ subscription_form type="#subscription_type#" template="#template_name#"
                        submit_button="#submit_button_name#"
                        [total_field="#total_field_name#"]
                        [evaluate_field="#evaluate_button_name#"] }}

The statements that match rule 1 are: Login, Search and User.

Edit Statements

Old syntax:

1. <!** Edit #statement# #attribute# >
2. <!** Edit #statement# #attribute# #integer_value# >
3. <!** Edit #statement# #attribute# HTML #html_code# >

New syntax:

1. {{ camp_edit object="#statement#" attribute="#attribute#" }}
2. {{ camp_edit object="#statement#" attribute="#attribute#" }}
3. {{ camp_edit object="#statement#" attribute="#attribute#" html_code="#html_code#" }}

Select Statements⁞

Old syntax:

1. <!** Select #statement# #attribute# >
2. <!** Select User gender #male_name_string# #female_name_string# >

New syntax:

1. {{ camp_select object="#statement#" attribute="#attribute#" }}
2. {{ camp_select object="user" attribute="gender" male_name="#male_name_string#"
                  female_name="#female_name_string#" }}

EDIT