MarkupBundle

The MarkupBundle provides the feature of extending output formats as with different so called tags. These tags will be automatically parsed and replaced before the response will be sent.

Example

This example contains a sulu-related example. The tag sulu:link represents a link to another page. This tag will be replaced via a valid anchor where the href attribute contains the UUID of the page.

<html>
    <body>
        <sulu:link href="123-123-123" title="test-title" />
    </body>
</html>

Results into:

<html>
    <body>
        <a href="/test" title="test-title">Page Title</a>
    </body>
</html>

Extending

To enable replacement of your custom tags you can define a service which implements the TagInterface.

class LinkTag implements TagInterface
{
    /**
     * Returns new tag with given attributes.
     *
     * @param array $attributes attributes array of each tag occurrence.
     *
     * @return array Tag array to replace all occurrences.
     */
    public function parseAll($attributesByTag) {
        $result = [];
        foreach($attributesByTag as $tag => $attributes) {
            $url = ; // load url via uuid from document-manager
            $pageTitle = ...; // load page-title via uuid from document-manager

            $result[$tag] = sprintf('<a href="%s" title="%s">%s</a>', $url, $pageTitle, $attributes['content']);
        }

        return $result;
    }
}

When registering your service simple add the tag <tag name="sulu_markup.tag" tag="link"/>.

Note

In combination with the plugin-system of the CKEditor you can easily provide a user-interface to manage your custom tag.