SunSed helps you and advises you to avoid writing as much raw HTML as it is possible. This is where the HTML library of SunSed comes into play. A series of functions that allow you to create HTML elements through the syntax of SunSed.

However, SunSed also makes it easy to write out complex blocks of HTML in the middle of your SunSed code.

Create Any HTML Element

In addition to the many HTML functions that lets you quickly create the most widely used HTML tags (for example; html:div(), html:h1(), html:span() and etc.) the html:tag function allows you to create an HTML element with any tag name.

html:tag(name: "mynav", content: "Content", attributes: ["id" => "navigation"], self_closing: FALSE )
#=> '<mynav id="navigation">Content</mynav>'

Add Attributes

To add attributes to HTML elements, you need to pass the desired attributes as a part of an Associative Array with the attribute name as the string index of each value.

$attributes = [
    "id" => "myElement",
    "class" => "myClass",
    "style" => "border: 1px solid red;"
html:div(content: "Hello There", attributes: $attributes)
#=> '<div id="myElement" class="myClass" style="border: 1px solid red">Hello There<div>'

Print HTML Functions

In addition to PRINT and :: (which is the shorthand for PRINT) you can also use the following method for calling HTML functions.

PRINT html:h1("Header One")
#=> '<h1>Header One<h1>'

:: html:h1("Header One")
#=> '<h1>Header One<h1>'

::h1 "Header One"
#=> '<h1>Header One<h1>'

::div "hello", attributes: ["style" => "color: red"]
#=> '<div style="color: red">hello</div>'

As shown in the above example, you omit the parenthesis and use a comma to separate the function's arguments.

Capture HTML as a SunSed Variable

In rare complex cases where writing pure HTML is preferred, SunSed allows you to easily store such HTML as a variable using the capture object start and end. Type an underscore (_), and the shortcut for creating a capture object start and end will appear in the pop-up.

    <div id="custom_html">Hello There</div>
$captured_div = $_;

::div $captured_div
#=> '<div><div id="custom_html">Hello There</div></div>'
Copyright © SunSed LLC 2013-2022 All rights reserved.