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

Documention: Relative Twig Paths #576

Open
thiagodemellobueno opened this issue Jun 15, 2018 · 19 comments
Open

Documention: Relative Twig Paths #576

thiagodemellobueno opened this issue Jun 15, 2018 · 19 comments

Comments

@thiagodemellobueno
Copy link
Contributor

We've known about KSS not supporting namespaces,
But since the latest version of jstransformers-twig it seems like ow the prototype doesn't support relative paths, which puts us in a bit of a binnd.

@RobLoach
Copy link
Contributor

RobLoach commented Jul 4, 2018

After some investigation, it seems relative paths don't really work in general. Updated the namespace usage, and I'll push out a KSTAT update with it.

Use @kalastatic or the other namespaces. We should add some more docs about it too.

@RobLoach RobLoach changed the title Pathing issues Documenation: Relative Twig Paths Jul 4, 2018
@thiagodemellobueno
Copy link
Contributor Author

thiagodemellobueno commented Jul 4, 2018 via email

@RobLoach
Copy link
Contributor

RobLoach commented Jul 4, 2018

Quite possibly! May need to update Twig in KSS too.

@thiagodemellobueno
Copy link
Contributor Author

thiagodemellobueno commented Jul 4, 2018 via email

@RobLoach
Copy link
Contributor

RobLoach commented Jul 4, 2018

The namespaces are declared across both KSTAT and KSS, but you'll have to....

  1. Update Kalastatic to 4.1.0-alpha.1
  2. Declare them in both pluginOpts and kss in kalastatic.yml
  3. Have them relative from the src directory

You'll see an example in https://github.com/kalamuna/kalastatic/blob/master/docs/4-Prototyping.md#namespaces

@soniktrooth
Copy link
Contributor

nice 👍

@RobLoach RobLoach changed the title Documenation: Relative Twig Paths Documention: Relative Twig Paths Jul 7, 2018
@timwasson
Copy link

timwasson commented Jul 18, 2018

I'm having namespace problems as well. I have upgraded to kalastatic 4.1.0-alpha.1 but I get errors like this when building:

Error parsing twig template site-browse-list.html.twig:
TwigException: Unable to find template file @kalastatic/icons/icon__save.svg

This worked until very recently. Is it because I can't include SVGs inline with recent kalastatic updates? I used to print out SVGs inline like this:

{% include '@kalastatic/icons/icon__facebook.svg' %}

Is there anything that can be done to include these SVGs inline as I used to? If I rename the file to icon__facebook.svg.twig I no longer get that "unable to find" error, I get this build error:

Error: Invalid result object from transform.
    at normalize (/Users/timwasson/Documents/CFR/fa-d8/src/web/themes/fa/node_modules/jstransformer/index.js:64:11)
    at tryCallOne (/Users/timwasson/Documents/CFR/fa-d8/src/web/themes/fa/node_modules/promise/lib/core.js:37:12)
    at /Users/timwasson/Documents/CFR/fa-d8/src/web/themes/fa/node_modules/promise/lib/core.js:123:15
    at flush (/Users/timwasson/Documents/CFR/fa-d8/src/web/themes/fa/node_modules/asap/raw.js:50:29)
    at process._tickCallback (internal/process/next_tick.js:61:11)

    at ChildProcess.exithandler (child_process.js:282:12)
    at ChildProcess.emit (events.js:182:13)
    at maybeClose (internal/child_process.js:957:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:246:5)

@RobLoach
Copy link
Contributor

RobLoach commented Jul 18, 2018

Correction... You're on the latest.. Thanks.

What's in your kalastatic.yml?

@timwasson
Copy link

Do you mean 4.0.0-alpha3? I just tried that, I'm getting the same errors. I do not see 4.1.0-alpha.3 on Github or via NPM.

@RobLoach
Copy link
Contributor

RobLoach commented Jul 18, 2018

Yes, apologies, read 4.0.0 instead of 4.1.0 👍 .... Thanks.

  • Are you changing the default namespaces anywhere?
  • Is there anything else in your log?

@timwasson
Copy link

timwasson commented Jul 18, 2018

No, I didn't change the defaults although I did try to fix them via the kalastatic.yml settings. It kept dying with an error on me, although I think I did stumble upon the proper settings. At least it's working for me now! I swear I tried this before posting here, but I guess it's just been one of those days. These are the settings that got it working for me:

pluginOpts:
  metalsmith-jstransformer:
      engineOptions:
        twig:
          namespaces:
            kalastatic: .

And:

kss:
  namespaces:
    kalastatic: .

This seems to have fixed the issue. I still have some adjustments to make with the Kalastatic update but I think I can take it from here. Thanks for your help!

@soniktrooth
Copy link
Contributor

soniktrooth commented Jul 18, 2018

I've only ever been able to include svgs by changing the file name to have a .twig extension and it works fine. I don't get that error that you are getting @timwasson
My understanding was that it was a twig limitation, not a Kalastatic one.
Related:
It's because of this issue I created this if you're interested: https://github.com/kalamuna/fontawesome-svg-twig

If you include it with NPM you can even set up a custom name space (@icon or whatever) and point it to the node module.

@timwasson
Copy link

That's interesting, @soniktrooth... With the above namespace updates I'm able to include SVGs inline with the .svg extension.

@soniktrooth
Copy link
Contributor

@timwasson that's great if it works. You're still getting errors though?

@timwasson
Copy link

No, adjusting the namespaces as above seems to have fixed the errors. The kalastatic update did cause me to have to do a few other updates, but no errors at this point.

@soniktrooth
Copy link
Contributor

ok cool. I'll have to update and see if I can include svgs on their own.

@RobLoach
Copy link
Contributor

Strange that Twig wouldn't allow .svg includes. @timwasson Have you found an issue in the twig queue about that?

@timwasson
Copy link

That's a question for @soniktrooth, I've never had a problem including SVGs.

@RobLoach
Copy link
Contributor

Does using source() work? https://twig.symfony.com/doc/2.x/functions/source.html

@RobLoach RobLoach removed their assignment Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants