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

add scripting field to card template #3762

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jakeprobst
Copy link
Contributor

scripting

@jakeprobst jakeprobst force-pushed the card_template_scripting branch 3 times, most recently from afa298d to dd8ad9f Compare January 23, 2025 03:43
@GithubAnon0000
Copy link
Contributor

GithubAnon0000 commented Jan 23, 2025

I think this would need scripting for the front and the back template, so that you have js for whatever happens on the front and js for whatever happens on the back.

@jakeprobst
Copy link
Contributor Author

In those cases you can just define two functions and call them in the corresponding template.

And to slip a slope just for fun: why not have front and back styling too? 🍃

@GithubAnon0000
Copy link
Contributor

GithubAnon0000 commented Jan 23, 2025

So you'd basically have e.g. the following in your front side?

<script>
    some_cool_js();
</script>

@jakeprobst
Copy link
Contributor Author

yep!

@dae
Copy link
Member

dae commented Jan 25, 2025

I'm afraid I'm not keen on this change. JS in card templates is difficult to update, and hard to support, and I think we may be better off moving in the opposite direction, moving the majority of styling and JS out of card templates, and into some sort of add-on/component system for templates, so deck authors and users can opt-in to particular styles or functionality, instead of pasting in code that is at risk of going stale.

@user1823
Copy link
Contributor

user1823 commented Jan 25, 2025

I can't comment on the overall cost vs benefit of this change.

But, this change makes using JS in an individual notetype easier. Currently, if I want to create or edit a JS function in my card template, I have to do that in multiple places — the Front templates and the Back templates of all the cards generated from that notetype (in my case, Forward and Reverse cards). After this change, I will have to make the change only at a single place.

This PR won't help much if the user wants to make the same change in multiple notetypes, though.

into some sort of add-on/component system for templates

This would be great, but based on the discussions in the Forums, this doesn't seem to be coming anytime soon.

@jakeprobst
Copy link
Contributor Author

jakeprobst commented Jan 25, 2025

My own use case that led to this PR is similar to what user1823 is saying. I have a note type that has 15+ cards each with mostly-the-same javascript on them, if I want to make a change I need to edit each one individually and it is quite tedious.

It is not like this PR is suddenly making scripting possible. A quick look at the forums and I found a variety of threads with scripting suggestions. Anki's ability to arbitrarily script the cards to add new features is a great feature. It just makes it more convenient to do. You could even argue that this makes updating outdated scripts easier to manage as the scripts are in one place, away from the templating, rather than mixed in and spread across a bunch of cards in the note.

discussions in the Forums

can you post the link? I couldn't find a topic that seemed relevant to this.

@dae
Copy link
Member

dae commented Jan 26, 2025

On the positive side, it saves you having to surround the code in script tags, and is a bit neater. On the negative side, it completely breaks on older Anki clients, and moves us further in the wrong direction. I'm afraid I don't think it's worth introducing breaking backwards-incompatible changes for a mild QoL improvement that will be temporary. For now, I'd recommend you either look into referencing a file in the media folder instead, or use one of the existing add-ons that can automatically update your templates with the contents of external files.

@user1823
Copy link
Contributor

can you post the link? I couldn't find a topic that seemed relevant to this.

https://forums.ankiweb.net/t/cross-platform-js-addons-for-the-reviewer/46082

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

Successfully merging this pull request may close these issues.

4 participants