9 Template Authors
lyse edited this page 1 week ago

Template Authors

This wiki page attempts to document all of the template variables and functions that can be used by teplate authors when customizing or creating a new theme.

Context Variables

The following are a list of variables that are available to use on every template, some values however depend on the "view" or things like whether a user is logged in, an admin user, etc.

Variable Description Usage Available In
Debug Whether the pod is running in debug mode or not {{ if $.Debug }} Globally
Logo The pod's configured logo (SVG) {{ $.Logo }} Globally
BaseURL The pod's configured base URL {{ $.BaseURL }} Globally
InstanceName The pod's configured name {{ $.InstanceName }} Globally
SoftwareVersion The version of yarnd running {{ $.SoftwareVersion }} Globally
TwtsPerPage The configured number of Twts per page to display (Pager) {{ $.TwtsPerPage }} Timeline, Profile
TwtPrompt A random text used for the placeholder of the Twt post form {{ $.TwtPrompt }} Timeline, Profile
MaxTwtLength The maximum permitted length of a Twt to limit the post form {{ $.MaxTwtLength }} Timeline, Profile
RegisterDisabled Whether the Pod has open registrations disabled {{ if $.RegisterDisabled }} Globally
OpenProfiles Whether the pod has open profiles enabled {{ if $.OpenProfiles }} Globally
DisableMedia Whether the pod has disabled all media processing {{ if $.DisabledMedia }} Globally
DisableFfmpeg Whether the pod has disabled all video/audio (ffmpeg) processing {{ if $.DisabledFfmpeg }} Globally
WhitelistedImages The pod's configured list of whitelisted domain regexes for inline image rendering {{ $.WhitelistedImages }} Manage Pod
BlacklistedFeeds The pod's configured list of blacklisted domain regexes for blacklisted feeds or pods {{ $.BlacklistedFeeds }} Manage Pod
EnabledFeatures The pod's configured list of enabled experimental features {{ $.EnabledFeatures }} Manage Pod
Timezones A list of all available major timezones in the world {{ range $.Timezones }} Settings
Reply The text to use for a new Twt's reply {{ $.Reply }}} Timeline, Profile
Username The username logged in, or null if anonymous {{ $.Username }} Globally
User The User object of the currently logged in user {{ $.User }} Globally
LastTwt The last types.Twt the user had posted {{ $.LastTwt }} Timeline, Profile
Profile The types.Profile object of the profile being viewed {{ $.Profile }} Profile
Authenticated Whether the user is currently authenticated {{ if $.Authenticated }} Globally
IsAdmin Whether the currently logged in user is the Pod Admin {{ if $.IsAdmin }} Globally
DisplayDatesInTimezone The User or Pod timezone preference for displaying date/times {{ $.DisplayDatesInTimezone }} Settings, Manage Pod
DisplayTimePreference The User or Pod time format preference (12h or 24h) {{ $.DisplayTimePreference }} Settings, Manage Pod
OpenLinksInPreference The User or Pod preference for opening links in Twts (new window or same window) {{ $.OpenLinksInPreference }} Settings, Manage Pod
Error Whether or not an error occurred {{ if $.Error }} Globally
Message The content of the error or success message (depending the value of .Error) {{ $.Message }} Globally
Lang The currently logged User's preferred language {{ $.Lang }} Globally
AcceptLangs The value of Accept-Language from a User-Agent/Browser request {{ $.AcceptLangs }} Globally
Theme The user's preferred theme (light, dark or auto) {{ $.Theme }} Globally
Commit The Git Commit SHA of the running Pod's yarnd software (See .SoftewareVersion) -- Used for cache busting static assets. {{ $.Commit }} Globally
Page The name of the current Markdown page (Support, Abuse, Private Policy, etc) {{ $.Page }} Pages
Content The rendered content of the Markdown page (Support, Abuse, Private Policy, etc) N/A Pages
Title The title of the current page ore view N/A Globally
Meta The meta tags of the current page or view N/A Globally
Links The extra links of the current page or view N/A Globally
Alternatives The alternative links of the current page or view N/A Globally
Twter The types.Twter object of the current logged User {{ $.Twter }} Globally
Twts The list of types.Twt for the current Timeline, Discover or Profile view {{ range $.Twts }} Timeline, Profile
LocalFeeds A list of all local feeds on the current Pod {{ range $.LocalFeeds }} Feeds
UserFeeds A list of all user owned feeds {{ range $.UserFeeds }} Feeds
FeedSources A list of all configured external feed sources for the Pod {{ range $.FeedSources }} Feeds
Pager The Pager object used for navigating pages of Twts on Timeline, Discover and Profile views {{ $.Pager }} Timeline, Profile
TimelineUpdatedAt The timestamp of when the Timeline view was last updated {{ $.TimelineUpdatedAt }} Globally
DiscoverUpdatedAt The timestamp of when the Discover view was last updated {{ $.DiscoverUpdatedAt }} Globally
LastMentionedAt The timestamp of when the User's Mentions view was last updated {{ $.LastMentionedAt }} Globally
SearchQuery The currently search query {{ $.SearchQuery }} Search
Bookmarklet The Javascript function for the current Pod's Bokmarklet that can be added to Browser Bookmark toolbars for quick easy "Share via " buttons. {{ $.Bookmarklet }} Settings
ReportNick The Username/Nickname of the User or Feed being reported {{ $.ReportNick }} Report
ReportURL The URL of the User or Feed being reported {{ $.ReportURL }} Report
PasswordResetToken The Password Reset token {{ $.PasswordResetToken }} Password Reset
CSRFToken The Cross-Site Request Forgery Token {{ $.CSRFToken }} All Forms

Template Functions

Function Description Usage
time Filter to display the relative time of a time.Time object {{ .TimelineUpdatedAt | time }}
hostnameFromURL Filter to extract the hostname/domain from a URL {{ $.Twt.Twter.URL | hostnameFromURL }}
prettyURL Filter to prettify a URL {{ $Source | prettyURL }}
isLocalURL Function to determine if a URL is local to the Pod {{ if isLocalURL $.Ctx.Twter.URL }}
formatTwt Function to format a Twt {{ formatTwt $.Twt $.User }}
unparseTwt Filter to unparsed a Twt mentions back to human friendly form {{ $.Twt.Text | unparseTwt }}
formatTwtContext Function to format the context of a Twt {{ formatTwtContext $.Twt $.User }}
getRootTwt Function to get the Root Twt of a yarn {{ getRootTwt $.Twt }}
formatForDateTime Function to format a Date/Time with the User's Time/Date preference {{ formatForDateTime $.Twt.Created $.User.DisplayTimeFormat }}
urlForConv Function to get the URL to a Yarn (unforked) {{ urlForConv $.Twt }}
urlForFork Function to get the URL to a Forked yarn {{ urlForFork $.Twt }}
urlForRootConv Function to get the URL to the Root of a yarn {{ urlForRootConv $.Twt }}
getConvLength Function to get the number of twts in a yarn {{ getConvLength $.Twt }}
getForkLength Function to get the number of forks of a Twt {{ getForkLength $.Twt }}
isAdminUser Function to determine of the user is the Pod Admin if {{ isAdminUser $.User }}
isSpecialFeed Function to determine if a named feed is one of the Admin personas or Automated feeds {{ if isSpecialFeed "support" }}
isFeatureEnabled Function to determine if a named experimental feature is enabled {{ if isFeatureEnabeld "foo" }}
html Filter to mark string as being HTML safe {{ "foo" | html }}
tr Function to translate UI elements to User's local language {{ $.tr "<key>" }}

In addition to the above listed functions, Sprig functions are also available to use in every template. Please refer to its documentation.