You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
All elements have one thing in common, all of them expect attributes.That is also the reason why it is the first parameter of all methods.You can specify attributes by an array. Where the key is the name of the attribute and the value the attribute value.If you do not want to specify attributes, leave the array empty.You can also omit the array if you do not use a callback.
The second and last parameter is the a callback function defined by the user.This lets you write a more generic code and allows the nesting of elements.With theyield keyword it is possible to write text into the current element without terminating the function.
Notice: Elements likebase,br,meta,area,input,wbr,hr,link,param,source,col andimg can not have a callback, only attributes.
The script will automatically detect if it is useful to escape a value or not.For example if you want to define ascript tag, it would not be useful to escape, because that destroys the logic of a script.But if you use apre tag it makes much more sense to escape the value. Also works for attributes.
echoH::html([],function() { H::head([]); H::body([],function () {// A really bad attribute value H::pre(['id' =>'"\'"'],function () {yield'<script>alert(1);</script>';// maybe some user code? });// Be careful with that and do not use user code in it H::script([],function () {yield'var x = Math.floor(Math.random() * 100);';yield'alert(0 < x < 100);'; }); });});