rsc

See also

Resources, The Zotonic data model, m_edge, m_media, m_rsc_gone.

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 of the resource model

A resource has the following properties accessible from the templates:

PropertyDescriptionExample value
idId of the page, an integer.42
titleTitle of the page. Returns a binary.<<”Breaking News”>>
short_titleShort title of the page. Used in menus. Returns a binary.<<”News!”>>
summarySummary of the page. Returns a binary or undefined.<<”Page summary.”>>
bodyThe HTML body of a page. Returns a binary or undefined.<<”<p>Hello</p>”>>
date_startStart 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_endEnd 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\}\}
nameUnique name of the page. Returns a binary or undefined. Valid characters are a-z, 0-9 and _<<”page_home”>>
page_pathUnique path of the page, used for url generation. Returns a binary or undefined. Valid characters are a-z, 0-9, / and -<<”/”>>
is_page_path_multipleAllow the page to be served on multiple URLsfalse
page_urlThe 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. The additional parameter with can be used to pass extra (optional) query arguments to the url, for instance: {{ id.page_url with t=now\|date:"U" }} {{ id.page_url with t="new" u=m.acl.user.id }}<<”/blog/42”>>
page_url_absThe absolute url of the page. Same as page_url but then with added protocol, hostname and port.<<”http://example.org/blog/42“>>
default_page_urlThe page without considering its page_path setting.<<”/page/42/my-slug”>>
is_authoritativeWhether this page originated on this site or is imported and maintained on another site. Return a boolean.true
uriThe 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_idId of the category the page belongs to. Returns an integer.102
categoryCategory record the page belongs to. Returns a property list.[\{id,102\},\{parent_id,undefined\], ... ,\{name, <<”person”>>\}\]
seo_noindexWhether to let search engines index this page. Returns a boolean or undefined.false
slugSlug used for url generation, appended to page urls. Binary or undefined. Valid characters are a-z, 0-9 and -<<”the-world-is-flat”>>
seo_descPage description for search engines. Returns a binary or undefined.<<”The truth about the world’s shape”>>
is_meCheck if this page is the current user’s person page. Returns a boolean.false
is_visibleCheck if this page is visible for the current user. Returns a boolean.true
is_editableCheck if this page is editable by the current user. Returns a boolean.false
is_linkableCheck if this page can be connected to another page. Returns a boolean.false
is_ingroupCheck if the current user is a member of the group the page belongs to. Returns a boolean.true
existsCheck if the page exists. Useful when checking if a named page is present or not. Returns a boolean.true
is_aReturns 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_catDirect check if a page is a certain category. More efficient then is_a. Example usage: {{ m.rsc[id].is_cat.person }}true
is_featuredIf featured checked or not. Returns a booleanfalse
is_protectedIf 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_dependentIf set to true then this page should only exist if there are incoming edges to this page. This flag is checked when an edge is deleted.true
is_publishedIf this page has been published. Returns a booleantrue
publication_startStart date of the publication period. Returns a datetime tuple.\{\{2009,12,24\},\{9,0,0\}\}
publication_endEnd date of the publication period. Returns a datetime tuple.\{\{9999,8,17\},\{12,0,0\}\}
is_published_dateIf 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_forVisibility level. Returns an integer. The actual meaning depends on the active ACL module.0
content_group_idContent group this resource belongs to. Defaults to the id of the content group named default_content_group or system_content_group for resources within the meta category. See mod_content_groups31415
oUsed 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)
sAccess 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)
opReturns a list of all predicates on edges from this page. The predicates are atoms.[about, related\]
spReturns a list of all predicates on edges to this page. The predicates are atoms.[author\]
predicates_editReturns 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\]
mediaReturn a list of all media ids connected to the page. The media are connected with the predicate “depiction”.[842,3078\]
mediumReturn 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…”>>, … \]
depictionReturn 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…”>>, … \]
image_urlAn url of the depiction, using the mediaclass image defined in mod_base<<”/image/...”>>
image_url_absThe absolute image_url, that is including https:<<”http://example.com//...”>>
thumbnail_urlAn url of the depiction, using the mediaclass thumbnail defined in mod_base<<”/image/...”>>
thumbnail_url_absThe absolute thumbnail_url, including https:<<”http://example.com//...”>>
emailE-mail address. Returns a binary or undefined.<<”me@example.com“>>
websiteURL of a website. Returns a binary or undefined.<<”http://zotonic.com“>>
is_website_redirectTell controller_page to redirect to the website URL instead of showing the HTML page.false
phonePhone number. Returns a binary or undefined.<<”+31201234567”>>
phone_altAlternative phone number. Returns a binary or undefined.undefined
phone_emergencyPhone number to call in emergencies.<<”112”>>
address_street_1Address line 1. Returns a binary or undefined.
address_street_2Address line 2. Returns a binary or undefined.
address_cityCity part of address. Returns a binary or undefined.
address_postcodePostcode part of address. Returns a binary or undefined.
address_stateState part of address. Returns a binary or undefined.
address_countryCountry part of address. Returns a binary or undefined.
mail_street_1Mailing address line 1. Returns a binary or undefined.
mail_street_2Mailing address line 2. Returns a binary or undefined.
mail_cityCity part of mailing address. Returns a binary or undefined.
mail_postcodePostcode part of mailing address. Returns a binary or undefined.
mail_stateState part of mailing address. Returns a binary or undefined.
mail_countryCountry part of mailing address. Returns a binary or undefined.
name_firstFirst name of person. Returns a binary or undefined.
name_middleMiddle name of person. Returns a binary of undefined.
name_surname_prefixPrefix for the surname of a person. Returns a binary or undefined.<<”van der”“>, <<”von”>>
name_surnameSurname or family name of person. Returns a binary or undefined.

Escaping

All strings that are stored inside resources are automatically HTML escaped. This means that these texts do not require any processing when they are being displayed in the browser, which causes major performance gains.

There are some fields in the resource that are exceptions to these rule, namely, the body field and any fields whose name ends in _html. These fields are assumed to contain HTML text and are sanitized on save instead of escaped.

Dates

Dates are stored as a standard Erlang date time tuple, for example {{2008,12,10},{15,30,00}}. Dates are stored and retrieved in UTC (universal time). When displaying a date, (e.g. with the date filter), the date is automatically converted into the time zone of the site or that of the user.

Printing all properties of a resource

In your templates, you can loop over the properties of a resource like this:

{% for k,v in m.rsc[id] %}
  {{ k }} - {{ v }} <br/>
{% endfor %}

And also using the print tag:

{% print m.rsc[id] %}

Edit on GitHub

Models category

Referred by

Resources

Resources are Zotonic’s main data unit. You may want to familiarise yourself with the Zotonic data model in the User…

Templates

Templates are text files marked up using the Zotonic template language. Zotonic interprets that mark-up to dynamically…

The Zotonic data model

Zotonic’s data model is a pragmatic implementation of the Semantic Web: a mixture between a traditional database and a…

edge

See also

Global template variables

These variables are always available for rendering in templates.

sort

The sort filter takes a list of items to sort. Items can be an ordinary list of terms, property lists, or maps. It can…

Template Best Practices and Pitfalls

This chapter lists some preferred solutions to common tasks and pitfalls you may encounter while developing with…

rsc_gone

See also