TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
MarkerBasedTemplateService Class Reference

Public Member Functions

 getSubpart ($content, $marker)
 
 substituteSubpart ($content, $marker, $subpartContent, $recursive=true, $keepMarker=false)
 
 substituteSubpartArray ($content, array $subpartsContent)
 
 substituteMarker ($content, $marker, $markContent)
 
 substituteMarkerArray ($content, $markContentArray, $wrap= '', $uppercase=false, $deleteUnused=false)
 

Static Public Member Functions

 substituteMarkerAndSubpartArrayRecursive ($content, array $markersAndSubparts, $wrap= '', $uppercase=false, $deleteUnused=false)
 

Detailed Description

Helper functionality for subparts and marker substitution

MYMARKER

Definition at line 22 of file MarkerBasedTemplateService.php.

Member Function Documentation

getSubpart (   $content,
  $marker 
)

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

Parameters
string$contentContent with subpart wrapped in fx. "###CONTENT_PART###" inside.
string$markerMarker string, eg. "###CONTENT_PART###
Returns
string

Definition at line 33 of file MarkerBasedTemplateService.php.

Referenced by MarkerBasedTemplateService\substituteMarkerAndSubpartArrayRecursive().

substituteMarker (   $content,
  $marker,
  $markContent 
)

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

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

Definition at line 170 of file MarkerBasedTemplateService.php.

substituteMarkerAndSubpartArrayRecursive (   $content,
array  $markersAndSubparts,
  $wrap = '',
  $uppercase = false,
  $deleteUnused = false 
)
static

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$contentThe content stream, typically HTML template content.
array$markersAndSubpartsThe array of single markers and subpart contents.
string$wrapA wrap value - [part1] | [part2] - for the markers before substitution.
bool$uppercaseIf set, all marker string substitution is done with upper-case markers.
bool$deleteUnusedIf set, all unused single markers are deleted.
Returns
string The processed output stream

Definition at line 261 of file MarkerBasedTemplateService.php.

References MarkerBasedTemplateService\getSubpart(), MarkerBasedTemplateService\substituteMarkerArray(), MarkerBasedTemplateService\substituteSubpartArray(), and GeneralUtility\trimExplode().

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$contentThe content stream, typically HTML template content.
array$markContentArrayThe 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$wrapA wrap value - [part 1] | [part 2] - for the markers before substitution
bool$uppercaseIf set, all marker string substitution is done with upper-case markers.
bool$deleteUnusedIf set, all unused marker are deleted.
Returns
string The processed output stream
See also
substituteMarker(), substituteMarkerInObject(), TEMPLATE()

Definition at line 194 of file MarkerBasedTemplateService.php.

References GeneralUtility\trimExplode().

Referenced by MarkerBasedTemplateService\substituteMarkerAndSubpartArrayRecursive().

substituteSubpart (   $content,
  $marker,
  $subpartContent,
  $recursive = true,
  $keepMarker = false 
)

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

Parameters
string$contentContent with subpart wrapped in fx. "###CONTENT_PART###" inside.
string$markerMarker string, eg. "###CONTENT_PART###
array$subpartContentIf $subpartContent happens to be an array, it's [0] and [1] elements are wrapped around the content of the subpart (fetched by getSubpart())
bool$recursiveIf $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 proceding subparts are ALSO substituted!
bool$keepMarkerIf set, the marker around the subpart is not removed, but kept in the output
Returns
string Processed input content

Definition at line 76 of file MarkerBasedTemplateService.php.

Referenced by MarkerBasedTemplateService\substituteSubpartArray().

substituteSubpartArray (   $content,
array  $subpartsContent 
)

Substitues multiple subparts at once

Parameters
string$contentThe content stream, typically HTML template content.
array$subpartsContentThe 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 150 of file MarkerBasedTemplateService.php.

References MarkerBasedTemplateService\substituteSubpart().

Referenced by MarkerBasedTemplateService\substituteMarkerAndSubpartArrayRecursive().