User Guides

Content Fields

Content fields are found in both sections and collections, they are responsible for storing, manipulating and providing access to the content stored within your website.


Using Content Fields

While content fields can provide their own custom methods, each field will always have an html() method defined, this is the method that you will primarily use to display the content fields data on your website.

For example, to display a content field's data on your website you could do this:

{% set section = cms.content.section("ExampleSection") %}
{{ section.exampleField.html() }}

Content Field Types

Each content field has a type assigned to it, there are multiple content types available that come built-in to LexasCMS. Every content type provides a custom UI that is specifically designed to ensure that dealing with that specific type of data is as simple as possible.

A list of the currently build-in content types can be found below:

Content Type Description
binary Allows files to be uploaded
collection Collection management content type
datetime Allows a date, time or both to be inputted
heading Serves no functional purpose, creates a heading/description in the admin panel
html Allows the use of an HTML WYSIWYG editor to input data
image Allows an image to be uploaded, cropped and resized
markdown Allows Markdown to be inputted and parsed
number Allows numbers to be inputted
password Allows data to be inputted and automatically hashed using bcrypt
related Creates relationships between collection items
select Allows the use of a static select input to input data
selectdata Creates relationships between collection items using a select input
text A basic single line text entry field
textarea A basic multi-line text entry field
toggle An on/off toggle input

Binary

Options

There are no extra options available to the binary content type.

Methods

The following methods are available for interacting with the binary content type.

Method Returns Description
getHref() string|null Returns the path to the current file, or null if no file is present.
getFilename() string|null Returns the filename of the current file, or null if no file is present.
getFilesize() integer|null Returns the size of the current file, or null if no file is present.
hasFile() boolean Returns true if a file is present, or false otherwise.

Collection

Options

The following options are available on collection content fields.

Option Data Type Default Value Description
definition string null The collection definition name to use.

Methods

See the collections section of the documentation for more information about using collections.


Date/Time

Options

The following options are available on datetime content fields.

Option Data Type Default Value Description
date boolean true Set this to false to disable the date picker
time boolean true Set this to false to disable the time picker

Methods

The following methods are available for interacting with the datetime content type.

Method Returns Description
getFormattedDate($format=null) string|null Returns the date the specified format, if no format is specified then an RFC 2822 formatted date will be returned.
getTimestamp() integer|null Returns current date as a UNIX timestamp.
hasDate() boolean Returns true if a date/time has been set, or false otherwise.

Heading

Options

There are no extra options available to the heading content type.

Methods

There are no methods available to the heading content type.


HTML

Options

There are no extra options available to the html content type.

Methods

There are no methods available to the html content type.


Image

Options

The following options are available on image content fields.

Option Data Type Default Value Description
widths array [] An array of widths that images should be resized to.
heights array [] An array of heights that images should be resized to.
sizes array [] An array of dimensions that images should be resized to. Each size should be provided as an array containing up to 3 keys (width, height and optionally position).

For example, a config of:
sizes: [ [200, 400, "top"] ]

Would produce an image 200x400px that had been cropped from the top of the image. Available positions are: top-left, top, top-right, left, center (default), right, bottom-left, bottom, bottom-right.

quality integer 100 The quality that images should be saved at, 0 is the lowest and 100 is the highest. This value is ignored when format is set to anything other than 'jpg'.
format string jpg Format that images will be saved in, possible options are 'png' and 'jpg'.
aspectRatio float null Aspect ratio that images must match, the UI will force the user to crop images that do not match the specified aspect ratio.

Methods

The following methods are available for interacting with the image content type.

Method Returns Description
width($width) $this Sets the width of the image that you would like to retrieve, this must be a value that has been specified in the content fields widths config.
height($height) $this Sets the height of the image that you would like to retrieve, this must be a value that has been specified in the content fields heights config.
size($width, $height, $position = 'center') $this Sets the size of the image that you would like to retrieve, this must be a size that has been specified in the content fields sizes config.
getFilename() string|null Returns the filename of the current image, or null if no image is present.
getCurrentSize() string|null Returns the current size of the image being retrieved, this will be either 'original' or the value specified by either the width(), height() or size() methods preceded by 'w', 'h' or 's' respectively.

Note: When using the size() method, the returned size will also be suffixed with the initials of the images crop position i.e. c for 'center', tl for 'top-left' etc.
getHref() string|null Returns the href of the current image.
getAlt() string|null Return the alt text for the current image.
getWidths() array Returns an array of the available widths.
getWidth() integer Returns the width of the image being retrieved.
getHeights() array Returns an array of the available heights.
getHeight() integer Returns the height of the image being retrieved.
getSizes() array Returns an array of the available sizes.
getSize() array Returns the size of the image being retrieved.
hasImage() boolean Returns true if an image is present, or false otherwise.
getDataURI() string|null Returns the base64 encoded data URI for the current image, or null if no image is present.

Markdown

Options

There are no extra options available to the markdown content type.

Methods

The following methods are available for interacting with the markdown content type.

Method Returns Description
getHTML() string|null Returns the parsed markdown as HTML
getMarkdown() string|null Returns the raw markdown

Number

Options

The following options are available on number content fields.

Option Data Type Default Value Description
min integer null The minimum allowed value.
max integer null The maximum allowed value.
decimals integer null The number of decimal places.

Methods

There are no methods available to the number content type.


Password

Options

There are no extra options available to the password content type.

Methods

The following methods are available for interacting with the password content type.

Method Returns Description
compare($value) boolean Returns true if the provided value matches the saved value, otherwise returns false.

Options

The following options are available on related content fields.

Option Data Type Default Value Description
collection string null The collection definition to relate items from.
collectionField string null The collection item field to search for related items by.

Methods

The following methods are available for interacting with the related content type.

Method Returns Description
addItem($uuid) boolean Adds a related item with the provided UUID.
removeItem($uuid) boolean Removes the related item with the provided UUID.
hasItem($uuid) boolean Returns true if a related item with the provided UUID exists.
reorderItem($uuid, $position) boolean Reorders the related item with the provided UUID to the specified position.

Select

Options

The following options are available on select content fields.

Option Data Type Default Value Description
options array [] The options available to choose from.
multiple boolean false Set this to true to enable selection of multiple options.

Methods

The following methods are available for interacting with the select content type.

Method Returns Description
isMultiple() boolean Returns true if the select content type is in multiple mode, otherwise returns false.

Select Data

Options

The following options are available on selectdata content fields.

Option Data Type Default Value Description
collection string null The definition name of the collection to retrieve the options from.
collectionField string null The collection item field to display in the UI.
multiple boolean false Set this to true to enable selection of multiple options.

Methods

The following methods are available for interacting with the selectdata content type.

Method Returns Description
isMultiple() boolean Returns true if the select content type is in multiple mode, otherwise returns false.

Text

Options

The following options are available on text content fields.

Option Data Type Default Value Description
limit integer null Enforces a limit on the amount of text that can be inputted.

Methods

There are no methods available to the text content type.


Textarea

Options

The following options are available on textarea content fields.

Option Data Type Default Value Description
limit integer null Enforces a limit on the amount of text that can be inputted.
rows integer null The number of rows that the textarea UI should be

Methods

There are no methods available to the textarea content type.


Toggle

Options

There are no extra options available to the toggle content type.

Methods

The following methods are available for interacting with the toggle content type.

Method Returns Description
isEnabled() boolean Returns true if the field is in the 'on' position, otherwise returns false.