Helper Functions
The seomatic.helper
functions are utilities that can help with pagination, previews, and preparing text and Assets.
seomatic.helper.paginate(PAGEINFO)
– Given thePAGEINFO
variable from the{% paginate %}
tag as described here, this will properly set thecanonicalUrl
, as well as adding the<link rel='prev'>
and<link rel='next'>
tags for you.seomatic.helper.isPreview()
– Returnstrue
if the current request is a preview,false
if it is not.seomatic.helper.sameAsByHandle(HANDLE)
– Returns an array of information about the Same As URLs site specified inHANDLE
. Here’s an example of the information in the returned array:phparray (size=4) 'siteName' => string 'Twitter' 'handle' => string 'twitter' 'url' => string 'https://twitter.com/nystudio107' 'account' => string 'nystudio107'
seomatic.helper.truncate(TEXT, LENGTH, SUBSTR)
– Truncates theTEXT
to a givenLENGTH
. IfSUBSTR
is provided, and truncating occurs, the string is further truncated so that the substring may be appended without exceeding the desired length.seomatic.helper.truncateOnWord(TEXT, LENGTH, SUBSTR)
– Truncates theTEXT
to a givenLENGTH
, while ensuring that it does not split words. IfSUBSTR
is provided, and truncating occurs, the string is further truncated so that the substring may be appended without exceeding the desired length.seomatic.helper.getLocalizedUrls(URI, SITE_ID)
– Return a list of localized URLs for a givenURI
that are in theSITE_ID
site’s group. BothURI
andSITE_ID
are optional, and will use the current request’sURI
and the current site’sSITE_ID
if omitted.seomatic.helper.loadMetadataForUri(URI, SITE_ID)
– Load the appropriate meta containers for the givenURI
and optionalSITE_ID
.seomatic.helper.sitemapIndexForSiteId(SITE_ID)
– Get the URL to theSITE_ID
s sitemap indexseomatic.helper.extractTextFromField(FIELD)
– Extract plain text from a PlainText, Redactor, CKEdtior, Tags, Matrix, or Neo field.seomatic.helper.extractKeywords(TEXT, LIMIT)
– Extract up toLIMIT
most important keywords fromTEXT
.seomatic.helper.extractSummary(TEXT)
– Extract the most important 3 sentences fromTEXT
.seomatic.helper.socialTransform(ASSET, TRANSFORMNAME)
– Transform theASSET
(either an Asset or an Asset ID) for social media sites inTRANSFORMNAME
; valid values arebase
,facebook
,twitter-summary
, andtwitter-large
.seomatic.helper.seoFileLink(FILE_URL, ROBOTS, CANONICAL, INLINE)
– Generates a link to a local or remote file that allows you to set theX-Robots-Tag
header viaROBOTS
(defaults toall
) andLink
canonical header viaCANONICAL
(defaults to''
) as per Advanced rel="canonical" HTTP Headers.INLINE
controls whether the file will be displayed inline or downloaded. If any values are empty''
, the headers will not be included.seomatic.helper.sanitizeUserInput(TEXT)
– Sanitize theTEXT
by decoding any HTML Entities, URL decoding the text, then removing any newlines, stripping HTML tags, stripping Twig tags, and changing single {}'s into ()'s.