Back to Main Site

Contents

Filter Reference

Working with Content

Content Loader Functions

Each view has a pre-defined variable called ContentLoader. This exposes several functions for querying the Optimizely repository.

(Clearly, most of these functions are thin wrappers around IContentLoader functionality.)

Get

The numeric ID of the content (required)
ObjectValue

Gets a specific content item by numeric ID.

Content #123 is named: {{ ContentLoader.Get(123).Name }}.

GetParent

The target page (required)
ObjectValue

Gets the parent of the target page.

<p>Return to {{ ContentLoader.GetParent(Model.CurrentPage) | link }}.</p>

GetStartPage

ObjectValue
The start page is named: {{ ContentLoader.GetStartPage().Name }}.

GetTopLevelPages

ArrayValue (ObjectValue)
<ul>
{% for page in ContentLoader.GetTopLevelPages() %}
  <li>{{ page | link }}</li>
{% endfor %}
</ul>

GetAncestors

The target page (required)
Boolean of whether to reverse the results (option, default: false)
ArrayValue (ObjectValue)

Returns the lineage of pages from the target page to start page (inclusive), ordered from “closest” (parent of the target page) to “furthest” (always start).

<ul>
{% for page in ContentLoader.GetAncestors(Model.CurrentPage, reverse:true) %}
  <li>{{ page | link }}</li>
{% endfor %}
</ul>

GetDescendants

The target page (required)
ArrayValue (ObjectValue)

Returns a flat list of all descendant pages. (If you want a nested list, use GetBranch.)

<ul>
{% for page in ContentLoader.GetDescendants(Model.CurrentPage) %}
  <li>{{ page | link }}</li>
{% endfor %}
</ul>

GetCrumbtrail

The target page (required)
Boolean of whether to include the start page (optional, default: true)
Boolean of whether to include the target page (optional, default: true)
ArrayValue (ObjectValue)

Essentially the same as GetAncestors, but always reversed and with some arguments to specify inclusion or exclusion of the start and target pages.

<ul class="breadcrumbs">
{% for page in ContentLoader.GetCrumbtrail(Model.CurrentPage, false, true) %}
  {% unless forloop.last %}
  <li>{{ page | link }}</li>
  {% else %}
  <li>{{ page.name }}</li>
  {% endif %}
{% endfor %}
</ul>

GetDepth

The target page (required)
NumberValue

Returns the numeric “depth” of the page. The start page is 0, the top-level pages are 1, etc.

<ul>
{% for page in ContentLoader.GetDescendants(Model.CurrentPage) %}
  <li class="depth-{{ ContentLoader.GetDepth(page) }}">{{ page | link }}</li>
{% endfor %}
</ul>

GetSiblings

The target page (required)
ArrayValue (ObjectValue)

Returns children of the same parent as the target page (exclusive of the target page).

<ul>
{% for page in ContentLoader.GetSiblings(Model.CurrentPage)
  <li>{{ page | link }}</li>
{% endfor %}
</ul>

GetBranch

The target page (required)
Maximum depth to recurse (optional; default, no limit)
Boolean whether to include the target page
ArrayValue (ObjectValue)

This returns a flat list which is a depth-first traversal of a branch of the content tree. The list is of INode objects. Those with an IsOpening value of true represent indents; those with an IsClosing value of true represent outdents. Those with a HasValue value of true contain a value in the Value property.

{% for node in ContentLoader.GetPageTree(ContentLoader.GetStartPage(), 2) %}
  {% if node.IsOpening %}<ul>{% endif %}
  {% if node.HasValue %}
    <li>{{ node.Value | link }}</li>
  {% endif %}
  {% if node.IsClosing %}</ul>{% endif %}
{% endfor %}

GetNearestOfType

The target page (required)
The type name you want (required)
ObjectValue

Climbs the tree from the target page until it finds a page of the specified type.

The parent section is {{ ContentLoader.GetNearestOfType(Model.CurrentPage, "SectionContainer") }}.

GetNearestWithValue

The target page (required)
The property name you want to inspect (required)
ObjectValue

Climbs the tree from the target page until it finds a page with a non-null value in the specified property. (This is handy for finding the nearest ancestor with a checkbox checked.)

The parent section is {{ ContentLoader.GetNearestWithValue(Model.CurrentPage, "NavAnchor") }}.

Content Filters

url

Resolves and returns the raw URL for the content item.

link

Creates an anchor tag to the content item. Optionally, you can provide a CSS class, a target attribute, or the text of the link (if not provided, the page name is used).

Visit the page at {{ page | link: class:"sibling", target:"_blank" }}.

Visit {{ page | link: text:"my page"}}.