-
Notifications
You must be signed in to change notification settings - Fork 37
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
Enable custom Twig tags #1
Comments
Hi @urbantrout, I'm counting 14 custom Twig tags in the Craft documentation. I'm not sure if I will find the time to implement them all. Can you prioritize them, maybe? If I do the first few, maybe you can try one of them yourself? |
@twbartel I may be able to help with this if you do implement a few... I think the ultimate issue may be (not only in Craft but in others) that plugins, 3rd party add-ons, etc. can add their own custom twig tags, so it may be impossible to whitelist them all within this plugin. Not sure if a prettier twig whitelist option is possible or not...? |
Hey @chasegiunta, that's very nice, thanks. The thing is, whitelisting alone is not enough. Every Twig tag potentially comes with its own structure. For example, while a In principle, this is taken care of, because this Prettier plugin is itself pluggable. For example, in our codebase, we have an const compatPlugin = require('../melody-plugin-orchestra-compat');
const prettier = require('prettier');
const { group, concat, line, indent } = prettier.doc.builders;
const {
STRING_NEEDS_QUOTES,
EXPRESSION_NEEDED,
} = require('prettier-plugin-twig-melody');
const printIconTag = (node, path, print) => {
...
};
module.exports = {
melodyExtensions: [compatPlugin],
printers: {
IconTag: printIconTag,
},
}; So, a plugin to this plugin exports |
Hello @chasegiunta and @urbantrout, I started a separate repository which is an extension to this plugin: https://github.com/twbartel/prettier-twig-craft-cms This can now be pulled into a project as an additional dev dependency, in case this project uses Craft CMS. So far, I implemented only the |
@twbartel Holy cow, after looking at that first Let me ask you this, and forgive me if I'm being naive but, rather than explicitly building a plugin/extension for each tag, could they be vague enough to where those that follow a similar structure could be all in one? There's several that follow the same tag structure as The |
You are right, this can definitely be abstracted and simplified, maybe even to the point where you can add a whitelist in the configuration - at least, for simple tags like |
Cheers for at least trying to take this on @twbartel ! Here is hoping for some kind of universal whitelist. Just tested this, and sadly it broke on most of 100 templates in Craft. |
Update to everyone interested: I'm very close to being able to handle custom Twig tags in an easy way. Waiting for trivago/melody#154 to be merged into Melody master, then I can merge some functionality into this project. Stay tuned! |
@twbartel That's great news! Super appreciative of your work! |
PR prepared, but not ready to merge yet: #35 How does this sound? |
Sounds very nice and pragmatic 🥳 |
Version |
@sjelfull can you give me some feedback if it's working with Craft for you now? |
Thanks, seems to be a huge improvement! I still have issues in most files. Will sort through what is syntax issues (like unclosed tags etc.) and then circle back. |
Great work! Got this error while testing: Error
Source file
.prettierrc
|
@rbrv Gonna look into that. However, it seems to be a different issue, so could you open a new one, please? |
Sure: #37 |
I get an error when I use CMS specific custom Twig tags, such as the
nav
andendnav
tag of Craft CMS (https://docs.craftcms.com/v2/templating/nav.html)Would be nice to extend this rule
The text was updated successfully, but these errors were encountered: