๐ŸŽฏ Specific Content (the one Function)

Last updated๏ผš2026-11-25

๐ŸŽฏ Specific Content (one function)

Anywhere in a template, fetch a single piece of content from the database via the one function. It returns an object whose fields match list pages (.Title, .Content, .Summary, .Image, etc.).

โšก Basic Syntax

<!-- Single content item: type + id -->
{{with one "type=news&id=1"}}
<h1>{{.Title}}</h1>
<div>{{.Content | safeHTML}}</div>
{{end}}

The with keyword: enters the object context, avoiding a variable prefix on every reference. When no content is found, nothing is output.

๐Ÿ“‹ Parameter Description

Parameter Description Example
type Content type: news / product / case / page type=news
id Content ID (required) id=12
site Site ID (multilingual, optional) site=2

๐Ÿ’ป Common Scenarios

<!-- Home page: pinned news from the "Company Updates" category -->
{{with one "type=news&id=10"}}
  <h3>{{.Title}}</h3>
  <p>{{.Summary}}</p>
  <a href="{{.URL}}">View Details โ†’</a>
{{end}}
<!-- Fetch a specific product (hero product on the home page) -->
{{with one "type=product&id=5"}}
  <div class="hero-product">
    <img src="{{.Thumbnail}}" alt="{{.Title}}">
    <h2>{{.Title}}</h2>
    <p>{{.Description}}</p>
  </div>
{{end}}

html <!-- Fetch the About Us single page --> {{with one "type=page&id=1"}} <h1>{{.Title}}</h1> <div>{{.Content | safeHTML}}</div> {{end}} โ† Content Detail Multiple Images โ†’

This site uses cookies for essential functionality and to improve your experience. See our Privacy Policy.