Campsite: TemplateObjects
Template Objects
In this article:
- Language
- Default Language
- Publication
- Default Publication
- Issue
- Default Issue
- Section
- Default Section
- Article
- Default Article
- Article Attachment
- Audio Attachment
- Article Comment
- Subtitle
- Image
- Topic
- Default Topic
- User
- Subscription
- Template
- Default Template
- URL
- Default URL
- Current List
- Login Action
- Search Articles Action
- Submit Comment Action
- Preview Comment Action
- Edit User Action
- Edit Subscription Action
The Campsite template engine stores the template environment in an object named 'campsite'. All Campsite properties and objects are attributes of $campsite object.
The $campsite object has the following attributes which are not objects:
- version: the Campsite version
- preview: true if the page was displayed in the preview window (by a Campsite staff user)
- prev_list_empty: true if a list was displayed before querying this attribute and this list was empty
Any Campsite object (e.g.: $campsite->language, $campsite->article) has the following functions:
- has_property("property_name")
Returns true when the object has the given property. This function can be used for dynamic article properties too.
E.g.: $campsite->article->has_property("name") will return true.
- same_as($campsite->other_object)
Returns true if the object variable given as a parameter points to the same data as the current object.
E.g.: {{ if $campsite->article->same_as($campsite->default_article) }} will return true if the current article was the same as the article defined at the beginning of the template. If both were undefined this function returns true.
Language
The "language" object is set at the beginning of the main template based on the request URL. This object can be changed using the set_language function. The language object has the following properties:
- name: language name
- number: language identifier in the Campsite database (integer value)
- english_name: language name in English
- code: language international code
- defined: boolean value (true/false) - true if the language was set in the current environment; false otherwise
If you want to verify whether the current environment language was the same as the initial language compare it to the default_language object:
{{ if $campsite->language == $campsite->default_language }}
...
{{ /if }}
If you want to display parts of your templates in a different language according to the language selected by the user, you can use something similar to the following code. This snippet was used for a bilingual publication.
{{ if $campsite->language->code == "en" }}archive{{ else }}[trans]archive{{ /if }}
Default Language
The "default_language" object is set at the beginning of the main template based on the request URL and can not be modified. It has the same attributes as the language object (see "Language" in this chapter).
Publication
The "publication" object is set at the beginning of the main template based on the request URL. This object can be changed using the set_publication (
see "Set publication" in this chapter) function. The publication object has the following properties:
- name: publication name
- identifier: publication identifier in the Campsite database (integer value)
- default_language: the publication default language - object of type language (see "Language" in this chapter))
- site: publication site
- defined: boolean value (true/false) - true if the publication was set in the current environment; false otherwise
- public_comments: true if the public (anonymous readers) was allowed to post comments
- moderated_comments: true if the comments posted by the current reader will be moderated
- captcha_enabled: true if CAPTCHA will be used to detect spam
- subscription_currency: returns the currency used for subscription payments
- subscription_time_unit: returns the time unit (day, week, month, year) used to set the subscription length
- subscription_trial_time: returns the default time of the trial subscription in time units
- subscription_paid_time: returns the default time of the paid subscription in time units
- subscription_time: returns the default time of the subscription in time units; the subscription type should be defined through request parameters in the user form (see "Form: User" in this chapter)
- subscription_unit_cost: returns the cost of the time unit for the paid subscription for a single translation of the publication
- subscription_unit_cost_all_lang: returns the cost of the time unit for the paid subscription for all translations of the publication
For more details on these attributes
see also "Creating a Publication" chapter.
Default Publication
The "default_publication" object is set at the beginning of the main template based on the request URL and can not be modified. It has the same attributes as the publication object (see "Publication" in this chapter).
Issue
The "issue" object is set at the beginning of the main template based on the request URL. This object can be changed using the set_issue function (
see "Set Issue" in this chapter). The issue object has the following properties:
- name: issue name
- number: issue identifier in the Campsite database (integer value)
- <date_attribute>: issue publish date field (year, month, day etc.)
- date: the issue publish date; you can customize the date display format by using the filter camp_date_format (see "Date Formatting" in this chapter)
- publish_date: alias of date
- template: the full path of the issue template file
- publication: the publication to which this issue belongs to - object of type publication (see "Publication" in this chapter)
- language: the issue language - object of type language (see "Language" in this chapter)
- url_name: the issue name used in URL display (see "Creating New Issue" chapter)
- defined: boolean value (true/false) - true if the issue was set in the current environment; false otherwise
- is_current: true if the issue set in the environment was the latest published issue
<date_attribute> may be one of the following:
- year: year (four digits)
- mon: month as a number (1..12)
- mday: day of the month as a number (1..31)
- yday: day of the year (1..366)
- wday: day of the week as a number (0=Sunday..6=Saturday)
- hour: hour (0..23)
- min: minute (two digits)
- sec: seconds (two digits)
- mon_name: name of the month
- wday_name: day of the week
Default Issue
The "default_issue" object is set at the beginning of the main template based on the request URL and can not be modified. It has the same attributes as the issue object (see "Issue" in this chapter).
Section
The "section" object is set at the beginning of the main template based on the request URL. This object can be changed using the set_section function (
see "Set Section" in this chapter). The section object has the following properties:
- name: section name
- number: section identifier in the Campsite database
- description: section description text
- url_name: the section name used in URL display (see Creating a section at "Creating a Publication" chapter)
- template: the full path of the issue template file
- publication: the publication to which this section belongs to - object of type publication (see "Publication" in this chapter)
- issue: the issue to which this section belongs to - object of type issue (see "Issue" in this chapter)
- language: the section language - object of type language (see "Language" in this chapter)
- defined: boolean value (true/false) - true if the section was set in the current environment; false otherwise
Default Section
The "default_section" object is set at the beginning of the main template based on the request URL and can not be modified. It has the same attributes as the section object (see "Section" in this chapter).
Article
The "article" object is set at the beginning of the main template based on the request URL. This object can be changed using the set_article function (
see "Set Article" in this chapter). The article object has the following properties:
Base properties/functions:
Comments related properties/functions:
- comments_enabled: true if comments were enabled for the article publication, article type and the current article
- comments_locked: true if comments were locked (meaning they can be listed but no new comments can be posted)
- comment_count: returns the number of the comments posted to the article and approved
Accessibility properties/functions:
- on_front_page: true if article front page flag was set
- on_section_page: true if article section page flag was set
- is_published: true if the article was published
- is_public: true if the article was accessible to the public
- is_indexed: true if the article was indexed by the search engine
- content_accessible: returns true if the content of the article is accessible for reading: either is public or the reader subscribed to the publication (see also "Editing Articles" and "Setting up Subscriptions")
Attachment related properties/functions:
- has_attachments: true if the article had attached files
- image: returns the image object that was defined in the template environment; if the image was not defined in the environment, returns the first image of the article; if the article didn't have any image attached returns an unset image object
- image_index: returns the index of the current image inside the article; if the image wasn't defined in the environment or it doesn't belong to the article returns null.
- has_image(<image_index>): true if the article had an attached image and it's index was equal to the given index
- image(<image_index>): returns the attached image having the given index; if no such image existed, returns an unset image object. This is a function so the image index is given in between brackets. E.g.: $campsite->article->image(3)
- image<image_index>: returns the attached image having the given index; if no such image existed, returns an unset image object. This is a property, not a function. E.g.: $campsite->article->image3
- topics_count: returns the number of topics attached to this article
- has_topics: true if the article had attached topics
- has_topic(<topic_identifier>): true if the article had the specified topic attached to it
Statistics properties/functions:
- reads: returns the number of readers that viewed this article since it was published
- request_object_id: the identifier used in statistics gathering
<date_attribute> may be one of the following:
- year: year (four digits)
- mon: month as a number (1..12)
- mday: day of the month as a number (1..31)
- yday: day of the year (1..366)
- wday: day of the week as a number (0=Sunday..6=Saturday)
- hour: hour (0..23)
- min: minute (two digits)
- sec: seconds (two digits)
- mon_name: name of the month
- wday_name: day of the week
Note regarding the attribute type->[<article_type>->]<article_type_attribute>:
Attributes which are body fields (content) have the following properties:
- all_subtitles: returns the whole content of the body field, not just the current subtitle
- first_paragraph: returns the first paragraph of the current subtitle
- subtitles_count: returns the number of the subtitles in the body field
- subtitle_number: returns the number of the current subtitle: 0 for the default subtitle, 1 for the first subtitle defined in the article content field etc.
- subtitle_is_current: true if the subtitle that would be displayed through the statement {{ $campsite->article-><article_type_attribute> }} is the same as the subtitle defined in the template environment (see also "Subtitle" and current_subtitle_no(<field_name>) above)
- has_previous_subtitles: true if the current subtitle from this field was not the first subtitle
- has_next_subtitles: true if the current subtitle from this field was not the last subtitle
E.g.: displaying the first paragraph of the dynamic field "content":
$campsite->article->content->first_paragraph
Note regarding the attribute type->[<article_type>->]<article_type_attribute>: Starting with Campsite 2.3.0 the table cell containing the image link in article body fields has the class cs_img and the cell containing the caption text has the class "caption"; this allows the web designer to change the layout of the article images by using a CSS file. The new image link has the following structure:
<table border="0" cellspacing="0" cellpadding="0" class="cs_img" align=left>
<tr>
<td align="center">
<img src="/get_img?NrArticle=143&NrImage=1" border="0"
hspace="5" vspace="5">
</td>
</tr>
<tr><td align="center" class="caption">Campsite team</td></tr>
</table>
Note regarding the attribute type->[<article_type>->]<article_type_attribute>: Starting with Campsite 2.3.3 the subtitle in the article body fields has the class articlesubhead; this allows the web designer to change the layout of the subtitles by using a CSS file. The subtitle anchor has the following structure:
<span class="articlesubhead">
<a name="a1.250_s1">Version 2.3.0 - 2.3.1</a>
</span>
The structure of the anchor name is:
a<language_identifier>.<article_number>_s<subtitle_number>
See also:
- Displaying Article Info
- Setting the Context Article
- Breaking an article into multiple parts
- Subtitle
- Subtitles List
- Current List
- Displaying Image Info
- Displaying Topics
- Topic
- Article Topics List
- Displaying Attachments
- Article Attachment
- Article Attachments List
- Comments
Default Article
The "default_article" object is set at the beginning of the main template based on the request URL and can not be modified. It has the same attributes as the article object.
Article Attachment
The "article_attachment" object is usually initialized inside a list of article attachments. It is not initialized at the beginning of the template and can not be initialized by other campsite function. The article attachment object has the following properties:
- identifier: the attachment identifier in the Campsite database (integer value)
- file_name: the name of the attached document
- mime_type: the mime type of the attached document
- extension: the file extension of the attached document
- description: the user filled description field of the attached document in the current language
- size_b: the size of the attached document in bytes
- size_kb: the size of the attached document in kilobytes
- size_mb: the size of the attached document in megabytes
- defined: boolean value (true/false) - true if the attachment was set in the current environment; false otherwise
Audio Attachment
The "audio_attachment" object is usually initialized inside a list of audio attachments. It is not initialized at the beginning of the template and can not be initialized by other campsite function. The audio attachment object has the following properties:
- title
- creator
- genre
- length
- year
- bitrate
- samplerate
- album
- description
- format
- label
- composer
- channels
- rating
- track_no
- disk_no
- lyrics
- copyright
- defined
Article Comment
The "article_comment" object is usually initialized inside a list of article comments. It can be initialized at the beginning of the template from the URL request but can not be initialized by other campsite function. The article comment object has the following properties:
- identifier: the numerical identifier of the article comment from the database
- real_name: the real name of the reader who posted the comment; the reader must be a registered campsite user; for anonymous readers this attribute will return an empty string
- nickname: the nickname of the reader who posted the comment
- reader_email: the email of the reader who posted the comment
- submit_date: the date and time the comment was submitted
- subject: the subject of the article comment
- content: the content of the article comment
- level: the level of the current comment in the tree structure of the comments
- defined: true if the comment object had a valid value
Subtitle
The "subtitle" object is usually initialized inside a list of subtitles. It can be initialized at the beginning of the template from the URL request but can not be initialized by other campsite function. The subtitle object has the following properties:
- number: the order number of the subtitle (starts from 0)
- name: subtitle name without the HTML formatting
- field_name: the article field name to which the subtitle belongs
- formatted_name: the subtitle name with HTML formatting
- content: the subtitle content
- count: the number of subtitles in the field content
- has_previous_subtitles: true if previous subtitles exist
- has_next_subtitles: true if subtitles exist after the current subtitle
See also Editing body-type fields: Working with the body field editor
("Using the WYSIWYG Article Editor" chapter).
Image
The "image" object is usually initialized inside a list of article images. It is not initialized at the beginning of the template and can not be initialized by other campsite function. The image object has the following properties:
- number: the image identifier in the images archive
- photographer: the name of the photographer that took the picture
- place: a short text containing the place where the picture was taken
- description: short description of the picture
- <date_attribute>: image creation date field (year, month, day etc.)
- date: image creation date; you can customize the date display format by using the filter camp_date_format (see "Date Formatting" in this chapter)
- article_index: returns the index of the current image inside the article defined in the environment; if the image wasn't defined in the environment, the article was not defined or the image didn't belong to the article returns null.
- imageurl: returns the URL of the current image
- thumbnailurl: returns the URL of the current image' thumbnail
- defined: boolean value (true/false) - true if the image was set in the current environment; false otherwise
<date_attribute> may be one of the following:
- year: year (four digits)
- mon: month as a number (1..12)
- mday: day of the month as a number (1..31)
- yday: day of the year (1..366)
- wday: day of the week as a number (0=Sunday..6=Saturday)
- hour: hour (0..23)
- min: minute (two digits)
- sec: seconds (two digits)
- mon_name: name of the month
- wday_name: day of the week
Topic
The "topic" object is usually initialized inside a "List of article topics" or a "List of subtopics". It can be initialized at the beginning of the template from the URL request or by using the "Set topic" campsite function. The topic object has the following properties:
- name: return the topic name in the current language defined in the template environment
- value: returns the topic value in the following format:
<topic_name_lang_code> = <topic_name>:<language_code>
- identifier: the topic identifier in the campsite database
- defined: true if the topic object had a valid value
Default Topic
The "default_topic" object is set at the beginning of the main template based on the request URL and can not be modified. It has the same attributes as the "Topic" object.
User
The "user" object is set at the beginning of the main template based on the session cookies or if one of the following actions took place: "Login action", "Edit user action". It can not be initialized by other campsite function. The user object has the following properties:
- identifier: the user identifier in the campsite database
- name: the user full name
- uname: the user login name
- gender: "M" or "F"
- email
- city
- str_address: street address
- state
- phone
- fax
- country: the country name
- country_code: the country code
- contact
- second_phone
- postal_code
- employer
- position
- interests
- how
- languages
- improvements
- field1
- field2
- field3
- field4
- field5
- text1
- text2
- text3
- pref1
- pref2
- pref3
- pref4
- title
- age
- defined: true if the user object had a valid value
- logged_in: true if the user was defined and authenticated
- blocked_from_comments: true if the user was blocked from posting comments
- subscription: returns the first subscription assigned to this user; unset if the user was not a reader
- is_admin: true if the user was not a reader
- has_permission(<permission_name>): true if the user was not a reader and had the given permission
Subscription
The "user->subscription" object is set at the beginning of the main template based on the session cookies or if the "Login action" took place. It can not be initialized by other campsite function.The subscription object has the following properties:
- identifier: the subscription identifier in the Campsite database
- currency: the currency identifier
- type: one of the following values: "trial", "paid"
- start_date: returns the start date of the subscription
- expiration_date: the expiration date in the format "yyyy-mm-dd hh:mm:ss"
- is_active: true if the subscription was active
- is_valid: true if the subscription was active and did not expire
- publication: returns the publication to which the subscription was made
- has_section(<section_number>): returns true if the subscription included the given section
- defined: true if the subscription object had a valid value
Template
The "template" object is set at the beginning of the main template based on the request URL. This object can not be changed using campsite functions. The template object has the following properties:
- name: the template file name
- identifier: the template identifier in the Campsite database
- type: returns one of the following values: issue, section, article, default, nontpl
- defined: true if the template object had a valid value
Default Template
The "default_template" object is set at the beginning of the main template based on the request URL and can not be modified. It has the same attributes as the template object (see "Default Template" in this chapter).
URL
The URL object follows the changes in the template environment, meaning that every time an object in the environment changed the URL object is updated. It has the following properties:
- is_valid: returns true if the URL was valid, false otherwise. On invalid URLs Campsite returns "404 not found" HTTP response. This option only works in 3.4.0 and newer versions.
{{ if !$campsite->url->is_valid }}
<h3>The requested page was not found.</h3>
{{ set_language name=`$campsite->publication->default_language->english_name` }}
{{ set_current_issue }}
{{ else }}
<!-- display content -->
{{ /if }}
- uri: returns the complete link URI and it is equivalent to:
{{ $campsite->url->uri_path }}?{{ $campsite->url->url_parameters }}
- uri_path: returns only the path part of the URI, the part before the parameters list. E.g.: if /en/1/2/3?param1=text was the full URI, uri_path is /en/1/2/3.
- url: returns the complete URL in the form:

- url_parameters: returns a string containing the runtime environment parameters in URL format
- form_parameters: the runtime environment parameters in HTML form format:
<input type="hidden" name="<param_name>" value="<param_value>">
- base: returns the URL base in the form: http[s]://<server_name>[:<port>]; the port is not displayed if it's value was the default value (80 for HTTP, 443 for HTTPS)
- path: equivalent to uri_path
- query: equivalent to url_parameters
- type: returns the identifier of the URL type set in the publication (see also "Creating a Publication" chapter)
- request_uri: equivalent to uri
- scheme: one of the following values: http, https
- host: the host name from the URL
- port: the port to which the request was made
- language: returns the language object corresponding to the language set in the URL; this value is always the same as the language in the environment (see "Language" in this chapter)
- publication: returns an object corresponding to the publication identified by the <server_name>; this value is always the same as the publication in the environment (see "Publication" in this chapter)
- issue: returns an object corresponding to the issue specified in the URL (unset if the issue was not specified); this value is always the same as the issue in the environment (see "Issue" in this chapter)
- section: returns an object corresponding to the section specified in the URL (unset if the section was not specified); this value is always the same as the section in the environment (see "Section" in this chapter)
- article: returns an object corresponding to the article specified in the URL (unset if the article was not specified); this value is always the same as the article in the environment (see "Article" in this chapter)
The URL object has the following functions:
- get_parameter(<parameter_name>): returns the value of the given parameter, null if not set
- set_parameter(<parameter_name>, <parameter_value>): set the given parameter to the given value
- reset_parameter(<parameter_name>): unset the given parameter
Default URL
The "default_url" object is set at the beginning of the main template based on the request URL and can not be modified. It has the same attributes as the url object (see "URL" in this chapter).
Current List
The "current_list" is defined inside a list statement only. If multiple lists are embedded then the current_list object refers to the most internal list in which the current_list object was used. E.g.:
{{ list_sections }}
{{ $campsite->current_list->index }} {{* refers to the sections list *}}
{{ list_articles }}
{{ $campsite->current_list->index }} {{* refers to the articles list *}}
{{ /list_articles }}
{{ $campsite->current_list->index }} {{* refers to the sections list *}}
{{ /list_sections }}The object has the following properties:
- column: if the "columns" parameter was set the column is incremented from 1 to "columns" and then reset to 1
- columns: the number of columns set in the list
- current: returns the current element in the list
- end: returns the index of the last element of the list
- index: the index of the current element in the list; starts from 1 and is computed from the list "start" plus the number of the element in the interval of the list that was displayed
- length: the number of the objects in the interval of elements to be displayed from the list
- limit: the maximum length of the list to be displayed (0 for unlimited)
- name
- row: starts from 1 and is incremented each time the column was reset
- start: the index of the first element to be displayed from the list
- count: the actual number of objects in the list (regardless of the limit set by the user)
- at_beginning: true if the current element was the first in the interval of elements to be displayed
- at_end: true if the current element was the last in the list
- has_next_elements: true if the list was limited and there are other elements after the last element of the interval to be displayed
- has_previous_elements: true if the list was limited and there are other elements before the first element of the interval to be displayed
- previous_start: the index of the first element from the previous interval of elements
- next_start: the index of the next element from the next interval of elements
- id: internal id of the list set by the template engine
Login Action
The "login_action" object is defined when a login action took place. It has the following properties:
- defined: true if a login action took place
- is_error: true if a login action took place and the result was an error
- error_code: error code of the login action; null if no login action took place
- error_message: error message of the login action; null if no login action took place
- ok: true if a login action took place and the result was success
- user_name: the login name of the user that attempted to log in
- remember_user: true if the remember user flag was set in the login form
Search Articles Action
The "search_articles_action" object is initialized when a search action took place. It has the following properties:
- defined: true if a search action took place
- is_error: true if a search action took place and the result was an error
- error_code: error code of the search action; null if no search action took place
- error_message: error message of the search action; null if no search action took place
- ok: true if a search action took place and the result was success
- search_phrase: the phrase for which the search was performed
- search_keywords: an array of keywords for which the search was performed
- match_all: true if the match all flag was set
- search_level: 0 for multiple publication search, 1 for current publication search, 2 for current issue search, 3 for current section search
- submit_button: the submit button text
- template: the template used on search form submit
Submit Comment Action
The "submit_comment_action" object is initialized when a comment form was submitted. It has the following properties:
- defined: true if a comment submit action took place
- is_error: true if a comment submit action took place and the result was an error
- error_code: error code of the comment submit action; null if no comment submit action took place
- error_message: error message of the comment submit action; null if no comment submit action took place
- ok: true if a comment submit action took place and the result was success
- subject: the comment subject as filled in the form
- content: the comment content as filled in the form
- reader_email: the comment reader email as filled in the form
Preview Comment Action
The "preview_comment_action" object is initialized when the preview button was clicked on a comment form. It has the following properties:
- defined: true if a comment preview action took place
- is_error: true if a comment preview action took place and the result was an error
- error_code: error code of the comment preview action; null if no comment preview action took place
- error_message: error message of the comment preview action; null if no comment preview action took place
- ok: true if a comment preview action took place and the result was success
- subject: the comment subject as filled in the form
- content: the comment content as filled in the form
- reader_email: the comment reader email as filled in the form
Edit User Action
The "edit_user_action" object is initialized when a user add/edit form was submitted. It has the following properties:
- defined: true if a user data submit action took place
- is_error: true if a user data submit action took place and the result was an error
- error_code: error code of the user data submit action; null if no user data submit action took place
- error_message: error message of the user data submit action; null if no user data submit action took place
- ok: true if a user data submit action took place and the result was success
- type: can take one of the following two values: "add" for user add submit, "edit" for an existing user data edit submit
- name: the user full name as filled in the form
- uname: the user login name as filled in the form
- password: the account password as filled in the form
- passwordagain: the password confirmation
- email: the user email as filled in the form
- city
- str_address
- state
- phone
- fax
- contact
- second_phone
- postal_code
- employer
- position
- interests
- how
- languages
- improvements
- field1
- field2
- field3
- field4
- field5
- text1
- text2
- text3
- country
- title
- gender
- age
- employertype
- pref1
- pref2
- pref3
- pref4
Edit Subscription Action
The "edit_subscription_action" object is initialized when a subscription form was submitted. It has the following properties:
- defined: true if a subscription submit action took place
- is_error: true if a subscription submit action took place and the result was an error
- error_code: error code of the subscription submit action; null if no subscription submit action took place
- error_message: error message of the subscription submit action; null if no subscription submit action took place
- ok: true if a subscription submit action took place and the result was success
- is_trial: true if the submitted subscription type was trial
- is_paid: true if the submitted subscription type was paid subscription
EDIT