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

How to reference elements within an SVG containing only <symbol> tags without parent <svg> tag? #6

Open
schel4ok opened this issue Feb 21, 2021 · 0 comments

Comments

@schel4ok
Copy link

schel4ok commented Feb 21, 2021

I have my svg sprite splitted into few blade.php files, which are then automatically combined during view rendering using blade engine in Laravel. So in svg sprites there is no first tag <svg>

Example
mydomain\resources\views\components\svg\header.blade.php

<div style="height: 0; width: 0; position: absolute; visibility: hidden;">
    <svg 
        version="1.1" 
        id="Capa_1"
        xmlns="http://www.w3.org/2000/svg"
        xmlns:xlink="http://www.w3.org/1999/xlink" 
        x="0px"
        y="0px" 
        xml:space="preserve" 
        viewBox="0 0 64 64"
    >

mydomain\resources\views\components\svg\basic.blade.php

<symbol id='arrow-right-long' viewBox='0 0 512 512'>
	<path .... />
</symbol>

<symbol id='arrow-right-short' viewBox='0 0 64 64'>
	<path .... />
</symbol>

<symbol id='building' viewBox='0 0 32 32'>
	<path .... />
</symbol>

mydomain\resources\views\components\svg\footer.blade.php

  </svg>
</div>

Here is the code to combine all these files into one svg sprite in blade template somewhere before </body>.

<x-svg.header/>
	<x-svg.basic/> // string to import basic.blade.php
	<x-svg.calc/>
	<x-svg.doors/>
	<x-svg.glass/>
	<x-svg.logo/>
	<x-svg.social/>
<x-svg.footer/>

So if I do like this in my css

.icon-building {
  content: url("../views/components/svg/basic.blade.php#building") no-repeat;
}

I see following error

> dev
> npm run development


> development
> mix

1 WARNING in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details)

ERROR in ./resources/css/app.css
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleParseError: Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <symbol id='arrow-right-long' viewBox='0 0 512 512'>
|
|       <path d='M506.134,241.843c-0.006-0.006-0.011-0.013-0.018-0.019l-104.504-104c-7.829-7.791-20.492-7.762-28.285,0.068c-7.792,7.829-7.762,20.492,0.067,28.284L443.558,236H20c-11.046,0-20,8.954-20,20c0,11.046,8.954,20,20,20h423.557l-70.162,69.824c-7.829,7.792-7.859,20.455-0.067,28.284c7.793,7.831,20.457,7.858,28.285,0.068l104.504-104c0.006-0.006,0.011-0.013,0.018-0.019C513.968,262.339,513.943,249.635,506.134,241.843z'/>
    at handleParseError (/home/http/app/node_modules/webpack/lib/NormalModule.js:804:19)
    at /home/http/app/node_modules/webpack/lib/NormalModule.js:905:5
    at processResult (/home/http/app/node_modules/webpack/lib/NormalModule.js:640:11)
    at /home/http/app/node_modules/webpack/lib/NormalModule.js:692:5
    at /home/http/app/node_modules/loader-runner/lib/LoaderRunner.js:406:3
    at iterateNormalLoaders (/home/http/app/node_modules/loader-runner/lib/LoaderRunner.js:232:10)
    at Array.<anonymous> (/home/http/app/node_modules/loader-runner/lib/LoaderRunner.js:223:4)
    at runCallbacks (/home/http/app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:27:15)
    at /home/http/app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:200:4
    at /home/http/app/node_modules/graceful-fs/graceful-fs.js:123:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:75:3)

1 ERROR in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details)
webpack compiled with 2 errors and 1 warning
npm ERR! code 1
npm ERR! path /home/http/app
npm ERR! command failed
npm ERR! command sh -c webpack "--progress" "--config=node_modules/laravel-mix/setup/webpack.config.js"

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/http/.npm/_logs/2021-02-21T14_04_55_043Z-debug.log
npm ERR! code 1
npm ERR! path /home/http/app
npm ERR! command failed
npm ERR! command sh -c mix

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/http/.npm/_logs/2021-02-21T14_04_55_133Z-debug.log

I found one way to eliminate error - is to move first svg tag to basic.blade.php, but I don't want to do that, because if I need svg symbol from another sprite like social.blade.svg I will face same problem and I cannot keep svg tag in each sprite file, because it will not work in my html template.

Is there another solution to reference elements within an SVG containing only <symbol> tags without parent <svg> tag?
Who cares about existence of <svg> tag in file if we just need to reference separate symbol elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant