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

Allow resource handles to be passed into svg() twig function #2838

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 8 additions & 3 deletions src/web/twig/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -806,14 +806,19 @@ public function shuffleFunction($arr)
/**
* Returns the (sanitized) contents of a given SVG file, namespacing any of its IDs in the process.
*
* @param string $svg The SVG file path or contents
* @param string|resource $svg The SVG file path or contents
* @param bool $sanitize Whether the file should be sanitized first
* @return \Twig_Markup|string
*/
public function svgFunction(string $svg, bool $sanitize = true)
public function svgFunction($svg, bool $sanitize = true)
{
// If it's a resource, read it until the end.
if (is_resource($svg))
{
$svg = stream_get_contents($svg);
}
// If we can't find an <svg> tag, it's probably a file path
if (stripos($svg, '<svg') === false) {
elseif (stripos($svg, '<svg') === false) {
$svg = Craft::getAlias($svg);
if (!is_file($svg) || !FileHelper::isSvg($svg)) {
return '';
Expand Down