Skip to content

Modifying the post teaser template

Ricky edited this page Sep 27, 2019 · 1 revision

Post teasers

A post teaser is the block of content shown for each blog post listed on a posts page (such as the default homepage or when viewing posts filtered by a tag). A teaser will almost always include the title of the post and a link through to read the full version.

The template for a post teaser can be modified through the CMS by a blog contributor (with appropriate permissions). From Settings > Posts is a code editor containing a Smarty template. Editing this code comes with a warning that any syntax errors in this template will break your blog and an error will be shown until the error in the template has been corrected.

Access requirements

Change settings permission

Variables

The following table describes the variables that can be used within the template for dynamic data

Variable name Datatype Description
$post \rbwebdesigns\HamletCMS\BlogPosts\Post
$blog \rbwebdesigns\HamletCMS\Blog\Blog
$config array
$userIsContributor boolean flag to determine if the user viewing the page is a contributor to the blog. Note - this will always be `false` when using custom domains.

Template snippets

Read the Semantic UI docs to discover how to format content without having to write your own CSS. When adding custom CSS it’s best added through the edit stylesheet setting page.

Formatting dates

{$post->timestamp|date_format:"%d/%m/%Y"}

Social media icons

{$encodedTitle = rawurlencode($post->title)}
{$encodedUrl   = rawurlencode("{$smarty.server.REQUEST_SCHEME}://{$smarty.server.SERVER_NAME}{$blog->relativePath()}/posts/{$post->link}")}
{$unencodedUrl = "{$smarty.server.REQUEST_SCHEME}://{$smarty.server.SERVER_NAME}{$blog->relativePath()}/posts/{$post->link}"}

<div class="six wide right aligned column social-icons">
    <a href="https://www.facebook.com/sharer/sharer.php?u={$encodedUrl}" onclick="window.open(this.href, 'height=600,width=400'); return false;" class="ui icon facebook button"><i class="facebook icon"></i></a>
    <a href="https://twitter.com/intent/tweet?url={$encodedUrl}&text={$encodedTitle}" target="_blank" class="ui icon twitter button"><i class="twitter icon"></i></a>
    <a href="mailto:?subject={$encodedTitle}&body={$encodedUrl}" class="ui icon grey button"><i class="mail icon"></i></a>
</div>