Open tanc opened 11 months ago
Hi @tanc, could you tell me the templates directory for your project, relative to the workspace directory?
The mechanism of definitionProvider defaults to workspaceDirectory/templates
. If your templates are stored there, the definition would work.
And have you tried to Ctrl+Click any of the template inclusion statements/functions?
e.g {{ include('template.html.twig') }}
. Click the template.html.twig
part.
Twig info not initialized
The extension calls a Symfony command to get custom developer-defined twig functions, globals and filters. Since your project is based not on the Symfony framework, this won't work. The other features should work as expected.
I will change the output message to better represent that behavior.
The templates directory is at web/themes/custom/[theme_name]
but with Drupal projects they can be set up in all sorts of ways and in different locations.
So I guess it would be good to have a workspace level config option for defining the templates directory or directories.
Control clicking includes don't work for me. But it could be because the use string interpolation with a variable, like: {{ include(directory ~ '/templates/misc/steps.html.twig') }}
Is it possible to get all template directories programmatically?
string interpolation with a variable
Yep, that's not supported
@tanc
workspace level config option for defining the templates directory or directories
What setting format could be good for Drupal case?
I'm thinking of adding a new extension setting:
"twiggy.tempateMappings": [
// include('template.html.twig') -> ./templates/template.html.twig
{ "alias": "", "path": "./templates" },
// include('@custom_theme_name/template.html.twig') -> ./web/themes/custom_theme_name/templates/template.html.twig
{ "alias": "@custom_theme_name", "path": "./web/themes/custom_theme_name/templates/" },
],
This would work for Drupal projects as well as for other non-Symfony projects.
But as far as I can see from Drupal quick start project (Download Drupal page, web/core/scripts/drupal quick-start demo_umami
), there is some layer of additional magic for templates resolving under the hood.
For example, in web/core/modules/node/templates/field--node--title.html.twig
the {% include "field.html.twig" %}
line should resolve to web/core/modules/system/templates/field.html.twig
, if my guess is correct.
Will take a second look here after #10 is resolved. Drupal experts are welcome to come here and drop a snippet close to this: https://github.com/moetelo/twiggy/issues/10#issuecomment-2039148859
Hi @moetelo, I'm trying your fork on a Drupal project. Opening the project and looking at the Twig Language Server output I see:
Language server started for: /my-file-path/my-project Twig info not initialized
Is there any way to tell why the Twig info is not initialising?