Jump to main content Jump to doc navigation

What is a Resource?

A resource is a representation of a page in MODx. There are different types of Resources, such as documents, weblinks, symlinks, actual files, or many other things. The default Resource type is a Document, and simply represents a webpage on your site.

There are 4 total types of Resources, and they are Documents, Weblinks, Symlinks, and Static Resources.

Each Resource also has a unique ID, or "Resource Identifier". This lets MODx know what Resource to fetch when you are loading a webpage. Also, when you're wanting to link between Resources, you should always use the ID to do so. That way MODx will generate the link and you will not have to worry about changed aliases, content types or anything - MODx will change your links also. Please see the Linking to Resources section below for more information on how to do this.

Managing Resources

Resources are shown in the Resources tree in the left-hand navigation of the manager. To edit one, simply click on the page you would like to edit. You can alternatively right-click the Resource and click 'Edit Resource'. This will load the Resource Edit page:

The content of the Resource can then be edited in the large content field in the bottom area. Other fields related to each Resource can also be edited via the tabs on the top of the page.

Resource Fields

Resources come packaged with a list of predetermined fields by default. They are:

General Resource Fields

Name Description
id
template
published
pagetitle
longtitle
description
introtext
alias
parent
link_attributes
menutitle
menuindex
hidemenu
content

Settings Resource Fields

Name Description
isfolder
searchable
cacheable
createdby
editedby
deleted
deletedby
publishedby
createdon
publishedon
editedon
pub_date
unpub_date

Using Resource Fields

Resource fields can be accessed from anywhere by using the Template Variable syntax, ie:

[[*pagetitle]] // renders the pagetitle.
[[*id]] // renders the Resource's ID
[[*createdby]] // renders the ID of the user who created this Resource

They can also have Output Filters applied to them:

// Renders a limited version of the introtext field.
// If it is longer than 100 chars, adds an ...
[[*introtext:ellipsis=`100`]]
// Grabs the user who last edited the Resource's username
[[*editedby:userinfo=`username`]]
// Grabs the user who published the Resource's email
[[*publishedby:userinfo=`email`]]

Accessing Resource Fields in a Snippet

Grabbing the Resource Fields in a Snippet is quite easy; MODx provides you with the Resource object in any Snippet, via the $modx->resource reference. For example, this example Snippet will return the current page's pagetitle reversed:

/* output the current Resource's pagetitle */
$output = $modx->resource->get('pagetitle');
return strrev($output);

Linking to a Resource

In MODx, links to Resources are dynamically managed via "Link Tags". They look like this:

[[~123]]

where '123' is the ID of the Resource to link to. You can put these tags anywhere, and MODx will dynamically render the URL for the Resource.

You can also get the Link Tag by dragging a Resource from the left tree into the content panel.

Also see Named Anchor.

Adding URL parameters in your Link Tag is quite simple in Revolution. Let's say we have Resource ID 42 that resolves to a URL of 'store/items.html'. We want to add a 'tag' parameter to the URL, with a value of 'Snacks' and a 'sort' parameter of 'Taste'. Here's how you'd do it:

[[~42? &tag=`Snacks` &sort=`Taste`]]

This would render as:

store/items.html?tag=Snacks&sort=Taste

Note that those are backticks instead of apostrophes.

You can specify the scheme for a Resource in your tag:

[[~123? &scheme=`https`]]

Would render the URL using 'https' instead of the scheme indicated by the current settings (i.e. system or context settings).

The available schemes are:

Name Description
-1
0
1
full
abs
http
https

See Also

  1. Content Types
  2. Named Anchor
  3. Static Resource
  4. Symlink
  5. Using Resource Symlinks
  6. Weblink