Skip to content

umbrellaTech/TagBuilder

Repository files navigation

TagBuilder

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Downloads

SensioLabsInsight

What is it?

TagBuilder is a component to help you to build html tags. But why use it to render tags instead of just write them? Well the tag builder sets a pattern of how we need to handle html elements, this avoids html errors and copy and paste code.

Install

{
    "require": {
        "umbrella/tag-builder": "~1.0"
    }
}

Usage

Build a link tag.

  $linkTag = new \Umbrella\TagBuilder\TagBuilder('a');
  
  //Adds a href attribute to the tag
  $linkTag->mergeAttribute('href', '#');
  
  //Adds a css class to the tag
  $linkTag->addCssClass('your-custom-css-class');
  
  //Adds a text or a html to some tag
  $linkTag->setInnerHtml('Your link text');
  
  //Renders the tag...
  echo $linkTag->toString(\Umbrella\TagBuilder\TagRenderMode::NORMAL);
  
  
  // ... or render like this
  echo $linkTag;
  
  //Both will print <a href="#" class="your-custom-css-class">Your link text</a>

We have many render modes available like:

\Umbrella\TagBuilder\TagRenderMode::NORMAL

\Umbrella\TagBuilder\TagRenderMode::START_TAG

\Umbrella\TagBuilder\TagRenderMode::END_TAG

\Umbrella\TagBuilder\TagRenderMode::SELF_CLOSING

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

TagBuilder is a component to help you to build html tags

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages