Documentation

Documentation

  • Documentation
  • Externable.com

›Templates

Introduction

  • Introduction to Externable

Setup

  • Registration
  • Creating Subscription
  • Renaming subscription
  • Setup URL
  • Connecting Dynamics
  • Setting up email
  • Provisioning instance
  • Starting and stopping instance
  • Connecting Custom Domain
  • Upgrading
  • Taking Backups
  • Restoring Backups
  • Resetting Instance
  • Changing Billing Address
  • Changing Subscription Plan

Portal Backoffice Basics

  • Login To Backoffice
  • Navigation In Backoffice
  • Adding & Managing Users

Creating Content

  • Creating, Saving and Publishing Content
  • Scheduling Posts
  • Content Versioning
  • Creating Content Templates
  • Restricting Access To Content
  • Creating Media
  • Sensitive Data
  • RichText Editor
  • Content Tree

Dynamics Integration

  • Default Template
  • Presenting Dynamics Data

    • Creating Dynamics Integrated Content
    • Extracting Dynamics Query

    Dynamics Forms

    • How Forms Work
    • Working with Formulas
    • Example - Create a Form

Languages

  • Enabling Languages
  • Creating Translations

Members

  • Creating Members In The Frontend
  • Creating Members in the Backend
  • Linking Members To Dynamics Contacts

Portal extension

  • Document Types
  • Data Types
  • Property Editors
  • Grid Editors
  • Macros
  • Relation Types
  • LogViewer
  • Templates

    • Templates
    • Razor Syntax
    • Rendering Content
    • Rendering Media
    • Rendering CSS & JS
    • Partial Views
    • Partial Macro Views
  • CSS customizations
  • JavaScript
  • Plugins Development

    • Plugins Development
    • MVC Controllers
    • WebAPI Controllers

Notes

  • Open Source Used

Rendering Content

The primary task of any template in Externable is to render the values of the current page or the result of a query against the content cache.

IMPORTANT: This article is about rendering Extrenable content page, each content page may talk to Dynamics. Learn More

Display a value in your template view

Each property in your document type has an alias, this is used to specify where in the template view to display the value.

<h1>@Model.Value("pageTitle")</h1>
<div>@Model.Value("bodyContent")</div>
<time>@Model.Value("articleDate")</time>

Specifying types of data

You can specify the type of data being returned to help you format the value for display, consider the publish date in our example:

<h1>@(Model.Value<string>("pageTitle"))</h1>
<div>@(Model.Value<HtmlString>("bodyContent"))</div>
<p>Article date: <time>@(Model.Value<DateTime>("articleDate").ToString("dd/MM/yyyy"))</time></p>

Using fall-back methods

The .Value() method has a number of optional parameters that support scenarios where we want to "fall-back" to some other content, when the property value does not exist on the current content item.

We can display a static, default value when a property value is not populated on the current content item:

@Model.Value("pageTitle", fallback: Fallback.ToDefaultValue, defaultValue: "Default page title")

A second supported method is to traverse up the tree ancestors to try to find a value. If the current content item isn't populated for a property, we can retrieve the value from the parent, grand-parent, or a higher ancestor in the tree. The first ancestor encountered that has a value will be the one returned.

@Model.Value("pageTitle", fallback: Fallback.ToAncestors)

If developing a multi-lingual site and fall-back languages have been configured, the third method available is to retrieve a value for a different language, if the language we are requesting does not have content populated. In this way, we could render a field containing French content for a property if it's populated in that language, and if not, default to English.

@Model.Value("pageTitle", "fr", fallback: Fallback.ToLanguage)

We can also combine these options to create some more sophisticated scenarios. For example we might want to fall-back via language first, and if that doesn't find any populated content, then try to find a value by traversing through the ancestors of the tree. We can do that using the following syntax, with the order of the fall-back options provided determining the order that content will be attempted to be retrieved:

@Model.Value("pageTitle", "fr", fallback: Fallback.To(Fallback.Language, Fallback.Ancestors))

In this further example, we are looking for content firstly on the current node for the default language, and if not found we'll search through the ancestors. If failing to find any populated value from them, we'll use the provided default:

@Model.Value("pageTitle", fallback: Fallback.To(Fallback.Ancestors, Fallback.DefaultValue), defaultValue: "Default page title")

Query content

In many cases you want to do more than display values from the current page, like creating a list of pages in a navigation. You can access content relative to the current page using methods such as Children(), Descendants() & Ancestors().

You can do this by querying content relative to your current page in template views:

<ul>
    @foreach (var child in Model.Children())
    {
        <li><a href="@child.Url">@child.Name</a></li>
    }
</ul>

You can use the Query Builder in the template editor to build more advanced queries.

← Razor SyntaxRendering Media →
  • Display a value in your template view
    • Specifying types of data
    • Using fall-back methods
  • Query content
Copyright © 2021