StackElement Object
You will come into contact with the StackElement object if you create your own PHP classes for HTML tags via the create html-tag CLI Command as explained on the previous page. This object will be passed as the second method of the render()
method within the PHP classes, and below explains all methods available to the object:
GetTag():string
Returns the name of the tag. For example, if the object is for an instance of <s:stock_quote...> tag, this would return "stock_quote".
getAttr(string $name):?string
Returns the value of the attribute within the tag, or null if attribute is not present.
getAttrAll(:array
Returns an associative array of all attributes passed within the tag.
getAttrString():string
Returns the string of all attributes before they were parsed into an associative array. For example, used within <s:if ...> tags to obtain the conditional.
getBody():string
Only applicable if the tag has an accompanying closing tag, and returns the body contents between opening and closing tags. Please note, this returns the tokenized version of the body meaning all <s:...> tags within will be tokenized. Please refer to the getChildren()
method below to see how to retrieve <s:...> tags within the body.
GetReplace:string
Should never need to be used, but same as getBody()
except it also returns the full contents including the <s:...> tags. This is what Syrus replaces in the tokenized template with the output of the tag.
getStack():Stack
Should never need to be used, but returns the full Stack
object which contains all StackElement
objects being parsed.
getChildren(string $child_tag):array
Returns an array of StackElement
objects for any child tags within the tag. For example, if the template code is:
<s:user_list>
<h3>User List</h3>
<s:user username="jsmith">
<s:user username="mike">
</s:user_list>
If the current StackElement
instance is of the <s:user_list> tag, you could retrieve its child tags with:
// $e = StackElement object
$children = $e->getChildren('user');
// $children array contains two elements, both StackElement objects of the <b>ERROR:</b> The template tag 'user' does not exist.<br /> tag.