Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML::svg #688

Open
wants to merge 1 commit into
base: 3.3/develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions classes/Kohana/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,33 @@ public static function image($file, array $attributes = NULL, $protocol = NULL,

return '<img'.HTML::attributes($attributes).' />';
}

/**
* Creates a svg link.
*
* echo HTML::svg('media/img/logo.svg', array('class' => 'my-class'));
*
* @param string $file file name
* @param array $attributes default attributes
* @return string
*/
public static function svg($file, array $attributes = NULL)
{
$ret = file_get_contents($file);

if ( ! empty($attributes))
{
$dom = new DOMDocument();
$dom->loadXml($ret);

foreach($attributes as $key => $value)
$dom->documentElement->setAttribute($key, $value);

$ret = $dom->saveHTML();
}

return $ret;
}

/**
* Compiles an array of HTML attributes into an attribute string.
Expand Down