‪TYPO3CMS  11.5
TYPO3\CMS\Core\Service\MarkerBasedTemplateService Class Reference

Public Member Functions

string getSubpart ($content, $marker)
 
string substituteSubpart ($content, $marker, $subpartContent, $recursive=true, $keepMarker=false)
 
string substituteSubpartArray ($content, array $subpartsContent)
 
string substituteMarker ($content, $marker, $markContent)
 
string substituteMarkerArray ($content, $markContentArray, $wrap='', $uppercase=false, $deleteUnused=false)
 
string substituteMarkerAndSubpartArrayRecursive ($content, array $markersAndSubparts, $wrap='', $uppercase=false, $deleteUnused=false)
 
string substituteMarkerArrayCached ($content, ?array $markContentArray=null, ?array $subpartContentArray=null, ?array $wrappedSubpartContentArray=null)
 
mixed substituteMarkerInObject (&$tree, array $markContentArray)
 
array fillInMarkerArray (array $markContentArray, array $row, $fieldList='', $nl2br=true, $prefix='FIELD_', $htmlSpecialCharsValue=false, $respectXhtml=false)
 

Protected Member Functions

TYPO3 CMS Core Cache Frontend FrontendInterface getCache ()
 
TYPO3 CMS Core Cache Frontend FrontendInterface getRuntimeCache ()
 

Detailed Description

Helper functionality for subparts and marker substitution

MYMARKER

Definition at line 26 of file MarkerBasedTemplateService.php.

Member Function Documentation

◆ fillInMarkerArray()

array TYPO3\CMS\Core\Service\MarkerBasedTemplateService::fillInMarkerArray ( array  $markContentArray,
array  $row,
  $fieldList = '',
  $nl2br = true,
  $prefix = 'FIELD_',
  $htmlSpecialCharsValue = false,
  $respectXhtml = false 
)

Adds elements to the input $markContentArray based on the values from the fields from $fieldList found in $row

Parameters
array$markContentArray‪Array with key/values being marker-strings/substitution values.
array$row‪An array with keys found in the $fieldList (typically a record) which values should be moved to the $markContentArray
string$fieldList‪A list of fields from the $row array to add to the $markContentArray array. If empty all fields from $row will be added (unless they are integers)
bool$nl2br‪If set, all values added to $markContentArray will be nl2br()'ed
string$prefix‪Prefix string to the fieldname before it is added as a key in the $markContentArray. Notice that the keys added to the $markContentArray always start and end with "###
bool$htmlSpecialCharsValue‪If set, all values are passed through htmlspecialchars() - RECOMMENDED to avoid most obvious XSS and maintain XHTML compliance.
bool$respectXhtml‪if set, and $nl2br is set, then the new lines are added with
instead of
Returns
‪array The modified $markContentArray

Definition at line 489 of file MarkerBasedTemplateService.php.

References TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger(), and TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

◆ getCache()

TYPO3 CMS Core Cache Frontend FrontendInterface TYPO3\CMS\Core\Service\MarkerBasedTemplateService::getCache ( )
protected

Second-level cache

Returns
‪\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface

Definition at line 516 of file MarkerBasedTemplateService.php.

Referenced by TYPO3\CMS\Core\Service\MarkerBasedTemplateService\substituteMarkerArrayCached().

◆ getRuntimeCache()

TYPO3 CMS Core Cache Frontend FrontendInterface TYPO3\CMS\Core\Service\MarkerBasedTemplateService::getRuntimeCache ( )
protected

First-level cache (runtime cache)

Returns
‪\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface

Definition at line 526 of file MarkerBasedTemplateService.php.

Referenced by TYPO3\CMS\Core\Service\MarkerBasedTemplateService\substituteMarkerArrayCached().

◆ getSubpart()

string TYPO3\CMS\Core\Service\MarkerBasedTemplateService::getSubpart (   $content,
  $marker 
)

Returns the first subpart encapsulated in the marker, $marker (possibly present in $content as a HTML comment)

Parameters
string$content‪Content with subpart wrapped in fx. "###CONTENT_PART###" inside.
string$marker‪Marker string, eg. "###CONTENT_PART###
Returns
‪string

Definition at line 37 of file MarkerBasedTemplateService.php.

Referenced by TYPO3\CMS\Core\Service\MarkerBasedTemplateService\substituteMarkerAndSubpartArrayRecursive().

◆ substituteMarker()

string TYPO3\CMS\Core\Service\MarkerBasedTemplateService::substituteMarker (   $content,
  $marker,
  $markContent 
)

Substitutes a marker string in the input content (by a simple str_replace())

Parameters
string$content‪The content stream, typically HTML template content.
string$marker‪The marker string, typically on the form "###[the marker string]###
mixed$markContent‪The content to insert instead of the marker string found.
Returns
‪string The processed HTML content string.
See also
substituteSubpart()

Definition at line 174 of file MarkerBasedTemplateService.php.

◆ substituteMarkerAndSubpartArrayRecursive()

string TYPO3\CMS\Core\Service\MarkerBasedTemplateService::substituteMarkerAndSubpartArrayRecursive (   $content,
array  $markersAndSubparts,
  $wrap = '',
  $uppercase = false,
  $deleteUnused = false 
)

Replaces all markers and subparts in a template with the content provided in the structured array.

The array is built like the template with its markers and subparts. Keys represent the marker name and the values the content. If the value is not an array the key will be treated as a single marker. If the value is an array the key will be treated as a subpart marker. Repeated subpart contents are of course elements in the array, so every subpart value must contain an array with its markers.

$markersAndSubparts = array ( '###SINGLEMARKER1###' => 'value 1', '###SUBPARTMARKER1###' => array( 0 => array( '###SINGLEMARKER2###' => 'value 2', ), 1 => array( '###SINGLEMARKER2###' => 'value 3', ) ), '###SUBPARTMARKER2###' => array( ), ) Subparts can be nested, so below the 'SINGLEMARKER2' it is possible to have another subpart marker with an array as the value, which in its turn contains the elements of the sub-subparts. Empty arrays for Subparts will cause the subtemplate to be cleared.

Parameters
string$content‪The content stream, typically HTML template content.
array$markersAndSubparts‪The array of single markers and subpart contents.
string$wrap‪A wrap value - [part1] | [part2] - for the markers before substitution.
bool$uppercase‪If set, all marker string substitution is done with upper-case markers.
bool$deleteUnused‪If set, all unused single markers are deleted.
Returns
‪string The processed output stream

Definition at line 264 of file MarkerBasedTemplateService.php.

References TYPO3\CMS\Core\Service\MarkerBasedTemplateService\getSubpart(), TYPO3\CMS\Core\Service\MarkerBasedTemplateService\substituteMarkerArray(), TYPO3\CMS\Core\Service\MarkerBasedTemplateService\substituteSubpartArray(), and TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

◆ substituteMarkerArray()

string TYPO3\CMS\Core\Service\MarkerBasedTemplateService::substituteMarkerArray (   $content,
  $markContentArray,
  $wrap = '',
  $uppercase = false,
  $deleteUnused = false 
)

Traverses the input $markContentArray array and for each key the marker by the same name (possibly wrapped and in upper case) will be substituted with the keys value in the array. This is very useful if you have a data-record to substitute in some content. In particular when you use the $wrap and $uppercase values to pre-process the markers. Eg. a key name like "myfield" could effectively be represented by the marker "###MYFIELD###" if the wrap value was "###|###" and the $uppercase boolean TRUE.

Parameters
string$content‪The content stream, typically HTML template content.
array$markContentArray‪The array of key/value pairs being marker/content values used in the substitution. For each element in this array the function will substitute a marker in the content stream with the content.
string$wrap‪A wrap value - [part 1] | [part 2] - for the markers before substitution
bool$uppercase‪If set, all marker string substitution is done with upper-case markers.
bool$deleteUnused‪If set, all unused marker are deleted.
Returns
‪string The processed output stream
See also
substituteMarker()
substituteMarkerInObject()

Definition at line 199 of file MarkerBasedTemplateService.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

Referenced by TYPO3\CMS\Core\Service\MarkerBasedTemplateService\substituteMarkerAndSubpartArrayRecursive(), and TYPO3\CMS\Core\Service\MarkerBasedTemplateService\substituteMarkerInObject().

◆ substituteMarkerArrayCached()

string TYPO3\CMS\Core\Service\MarkerBasedTemplateService::substituteMarkerArrayCached (   $content,
?array  $markContentArray = null,
?array  $subpartContentArray = null,
?array  $wrappedSubpartContentArray = null 
)

Multi substitution function with caching.

This function should be a one-stop substitution function for working with HTML-template. It does not substitute by str_replace but by splitting. This secures that the value inserted does not themselves contain markers or subparts.

Note that the "caching" won't cache the content of the substitution, but only the splitting of the template in various parts. So if you want only one cache-entry per template, make sure you always pass the exact same set of marker/subpart keys. Else you will be flooding the user's cache table.

This function takes three kinds of substitutions in one: $markContentArray is a regular marker-array where the 'keys' are substituted in $content with their values

$subpartContentArray works exactly like markContentArray only is whole subparts substituted and not only a single marker.

$wrappedSubpartContentArray is an array of arrays with 0/1 keys where the subparts pointed to by the main key is wrapped with the 0/1 value alternating.

Parameters
string$content‪The content stream, typically HTML template content.
array | null$markContentArray‪Regular marker-array where the 'keys' are substituted in $content with their values
array | null$subpartContentArray‪Exactly like markContentArray only is whole subparts substituted and not only a single marker.
array | null$wrappedSubpartContentArray‪An array of arrays with 0/1 keys where the subparts pointed to by the main key is wrapped with the 0/1 value alternating.
Returns
‪string The output content stream
See also
substituteSubpart()
substituteMarker()
substituteMarkerInObject()

Definition at line 356 of file MarkerBasedTemplateService.php.

References TYPO3\CMS\Core\Service\MarkerBasedTemplateService\getCache(), TYPO3\CMS\Core\Service\MarkerBasedTemplateService\getRuntimeCache(), and TYPO3\CMS\Core\Service\MarkerBasedTemplateService\substituteSubpart().

◆ substituteMarkerInObject()

mixed TYPO3\CMS\Core\Service\MarkerBasedTemplateService::substituteMarkerInObject ( $tree,
array  $markContentArray 
)

Substitute marker array in an array of values

Parameters
mixed$tree‪If string, then it just calls substituteMarkerArray. If array(and even multi-dim) then for each key/value pair the marker array will be substituted (by calling this function recursively)
array$markContentArray‪The array of key/value pairs being marker/content values used in the substitution. For each element in this array the function will substitute a marker in the content string/array values.
Returns
‪mixed The processed input variable.
See also
substituteMarker()

Definition at line 464 of file MarkerBasedTemplateService.php.

References TYPO3\CMS\Core\Service\MarkerBasedTemplateService\substituteMarkerArray().

◆ substituteSubpart()

string TYPO3\CMS\Core\Service\MarkerBasedTemplateService::substituteSubpart (   $content,
  $marker,
  $subpartContent,
  $recursive = true,
  $keepMarker = false 
)

Substitutes a subpart in $content with the content of $subpartContent.

Parameters
string$content‪Content with subpart wrapped in fx. "###CONTENT_PART###" inside.
string$marker‪Marker string, eg. "###CONTENT_PART###
string | array$subpartContent‪If $subpartContent happens to be an array, it's [0] and [1] elements are wrapped around the content of the subpart (fetched by getSubpart())
bool$recursive‪If $recursive is set, the function calls itself with the content set to the remaining part of the content after the second marker. This means that proceeding subparts are ALSO substituted!
bool$keepMarker‪If set, the marker around the subpart is not removed, but kept in the output
Returns
‪string Processed input content

Definition at line 80 of file MarkerBasedTemplateService.php.

Referenced by TYPO3\CMS\Core\Service\MarkerBasedTemplateService\substituteMarkerArrayCached(), and TYPO3\CMS\Core\Service\MarkerBasedTemplateService\substituteSubpartArray().

◆ substituteSubpartArray()

string TYPO3\CMS\Core\Service\MarkerBasedTemplateService::substituteSubpartArray (   $content,
array  $subpartsContent 
)

Substitutes multiple subparts at once

Parameters
string$content‪The content stream, typically HTML template content.
array$subpartsContent‪The array of key/value pairs being subpart/content values used in the substitution. For each element in this array the function will substitute a subpart in the content stream with the content.
Returns
‪string The processed HTML content string.

Definition at line 154 of file MarkerBasedTemplateService.php.

References TYPO3\CMS\Core\Service\MarkerBasedTemplateService\substituteSubpart().

Referenced by TYPO3\CMS\Core\Service\MarkerBasedTemplateService\substituteMarkerAndSubpartArrayRecursive().