m_rsc

  • Module: core

The main resource model, which is the central part of the Zotonic data model. This model provides an interface to all resource (“page”) information. It also provides an easy way to fetch edges from pages without needing to use the m_edge model.

Properties

All stored texts are HTML escaped, except for the body text which is stored as-is and assumed to be valid XHTML. Retrieved texts are always binaries. Dates are stored as a standard Erlang date time tuple, for example {{2008,12,10},{15,30,00}}. Retrieved dates are in the local time of the server.

A resource has the following properties accessible from the templates:

Property Description Example value
id Id of the page, an integer. 42
title Title of the page. Returns a binary. <<”Breaking News”>>
short_title Short title of the page. Used in menus. Returns a binary. <<”News!”>>
summary Summary of the page. Returns a binary or undefined. <<”Page summary.”>>
body The HTML body of a page. Returns a binary or undefined. <<”<p>Hello</p>”>>
date_start Start date when the page has a period. Examples are events or the birth date of a person. Returns a datetime tuple or undefined. {{2008,12,10},{15,30,00}}
date_end End date when the page has a period. Returns a datetime tuple or undefined. When there is a start date then there is also an end date. {{2009,12,5},{23,59,59}}
name Unique name of the page. Returns a binary or undefined. Valid characters are a-z, 0-9 and _ <<”page_home”>>
page_path Unique path of the page, used for url generation. Returns a binary or undefined. Valid characters are a-z, 0-9, / and - <<”/”>>
page_url The url of the page. Derived using the page’s category, the page id and its slug. Returns a non flattened list. Returns the binary page_path when it is set. <<”/blog/42”>>
page_url_abs The absolute url of the page. Same as page_url but then with added protocol, hostname and port. <<”http://example.org/blog/42“>>
default_page_url The page without considering its page_path setting. <<”/page/42/my-slug”>>
is_authoritative Whether this page originated on this site or is imported and maintained on another site. Return a boolean. true
uri The absolute unique uri of this resource. Refers to the “id” dispatch rule for authoritative (local) resources. Returns a binary. <<”http://example.com/id/42“>>
category_id Id of the category the page belongs to. Returns an integer. 102
category Category record the page belongs to. Returns a property list. [{id,102},{parent_id,undefined], ... ,{name, <<”person”>>}]
seo_noindex Whether to let search engines index this page. Returns a boolean or undefined. false
seo_title Title for on top of the browser window. Returns a binary or undefined. <<”Welcome Title”>>
slug Slug used for url generation, appended to page urls. Binary or undefined. Valid characters are a-z, 0-9 and - <<”the-world-is-flat”>>
seo_keywords Keywords for search engine optimization. List of keywords separated with commas. Returns a binary or undefined. <<”world, model, flat”>>
seo_desc Page description for search engines. Returns a binary or undefined. <<”The truth about the world’s shape”>>
is_me Check if this page is the current user’s person page. Returns a boolean. false
is_visible Check if this page is visible for the current user. Returns a boolean. true
is_editable Check if this page is editable by the current user. Returns a boolean. false
is_ingroup Check if the current user is a member of the group the page belongs to. Returns a boolean. true
exists Check if the page exists. Useful when checking if a named page is present or not. Returns a boolean. true
is_a

Returns a list of the category hierarchy the page belongs to. The list is suitable for indexing with category atoms.

Example usage: {{ m.rsc[id].is_a.article }}

[{text,true}, {article,true}]
is_cat

Direct check if a page is a certain category. More efficient then is_a.

Example usage: {{ m.rsc[id].is_cat.person }}

true
is_featured If featured checked or not. Returns a boolean false
is_protected

If this page is protected from deletion. Returns a boolean.

Resources are protected by a simple table called protect that prevents accidental deletions of rsc records. It does this by having a foreign key constraint that prohibits the deletion of the referred rsc record.

false
is_published If this page has been published. Returns a boolean true
publication_start Start date of the publication period. Returns a datetime tuple. {{2009,12,24},{9,0,0}}
publication_end End date of the publication period. Returns a datetime tuple. {{9999,8,17},{12,0,0}}
is_published_date If this page is published and the current date/time is within the set publication_start/end range. Note that no ACL checks are performed, use is_visible to check if a resource is visible for the current user. true
visible_for Visibility level. Returns an integer. 0 = world visible, 1 = only for logged on users, 2 = only for group members, 3 = only for current user. 0
o

Used to access the objects of page: the pages this page refers to. Returns a function which should be indexed with the edge’s predicate name (atom). When indexed the function will return a list of integers.

Example usage: {{ m.rsc[id].o.author[1].title }}

This returns the first author that is linked from this page.

fun(Predicate,Context)
s

Access the subjects of a page: the pages that are referring to this page. Returns a function which should be indexed with the edge’s predicate name (atom). When indexed the function will return a list of integers.

Example usage: {{ m.rsc[id].s.author[1].title }}

This returns the first article that links to me with a author connection.

fun(Predicate,Context)
op Returns a list of all predicates on edges from this page. The predicates are atoms. [about, related]
sp Returns a list of all predicates on edges to this page. The predicates are atoms. [author]
predicates_edit Returns a list of all allowed predicates from this page. Used for editing the page. Returns a list of predicate ids (in contrast with the atoms of op and sp). [308,300,304,303,302,300]
media Return a list of all media ids connected to the page. The media are connected with the predicate “depiction”. [842,3078]
medium Return a property list describing the file or medium attached to the page. A medium record is present for pages that are an image, video etc. Returns undefined when there is no medium defined. See the model m_media for more information. [ {id,512}, {filename, <<”2009/1…”>>, … ]
depiction Return the medium record that can be used for the image of a page. Either returns a medium page attached to the page or the medium record of the page itself. When no medium is found then undefined is returned. [ {id,512}, {filename, <<”2009/1…”>>, … ]
email E-mail address. Returns a binary or undefined. <<”me@example.com“>>
website URL of a website. Returns a binary or undefined. <<”http://zotonic.com“>>
phone Phone number. Returns a binary or undefined. <<”+31201234567”>>
phone_alt Alternative phone number. Returns a binary or undefined. undefined
phone_emergency Phone number to call in emergencies. <<”112”>>
address_street_1 Address line 1. Returns a binary or undefined.  
address_street_2 Address line 2. Returns a binary or undefined.  
address_city City part of address. Returns a binary or undefined.  
address_postcode Postcode part of address. Returns a binary or undefined.  
address_state State part of address. Returns a binary or undefined.  
address_country Country part of address. Returns a binary or undefined.  
mail_street_1 Mailing address line 1. Returns a binary or undefined.  
mail_street_2 Mailing address line 2. Returns a binary or undefined.  
mail_city City part of mailing address. Returns a binary or undefined.  
mail_postcode Postcode part of mailing address. Returns a binary or undefined.  
mail_state State part of mailing address. Returns a binary or undefined.  
mail_country Country part of mailing address. Returns a binary or undefined.  
name_first First name of person. Returns a binary or undefined.  
name_middle Middle name of person. Returns a binary of undefined.  
name_surname_prefix Prefix for the surname of a person. Returns a binary or undefined. <<”van der”“>, <<”von”>>
name_surname Surname or family name of person. Returns a binary or undefined.  

Table Of Contents

Previous topic

m_req

Next topic

m_rsc_gone

Versions

Actions