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

Introduce "thisTiddler" variable #7182

Merged
merged 9 commits into from May 6, 2023
Merged

Introduce "thisTiddler" variable #7182

merged 9 commits into from May 6, 2023

Conversation

Jermolene
Copy link
Owner

@Jermolene Jermolene commented Jan 5, 2023

This PR introduces a new system variable called thisTiddler that is set to the title of the tiddler that contains the text of the widget being rendered.

For example, within a template, thisTiddler contains the title of the template itself, even if it has been invoked with a different value for the currentTiddler variable. This makes it possible for templates to robustly include references to data that is stored in their own fields.

Note that invoking a macro does not change the value of thisTiddler. This means that it can be used by macro definitions to access the fields of the tiddler from which the macro was invoked. This will work even if there are intermediate macro invocations.

There is currently no way for a macro to access the title of the tiddler in which it was defined. Part of the issue is that macros are not necessarily defined in a tiddler at all; they are implemented as variables, and so can be dynamically computed.

Backwards compatibility considerations:

  • Will break some existing usages of a variable or parameter called “thisTiddler”
  • Tiddlers that previously would have parsed to an empty parse tree will now produce a single set widget to set thisTiddler. This might break code that tests for an empty parse tree (this is no longer the case since the refactor in a61d644)

Thanks to @ericshulman for the inspiration.

@vercel
Copy link

vercel bot commented Jan 5, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
tiddlywiki5 ✅ Ready (Inspect) Visit Preview May 6, 2023 10:43am

@Jermolene
Copy link
Owner Author

@ericshulman – I haven't added the docs for this yet. I wondered if you might be able to help with one or two examples that would be useful and instructive?

@pmario
Copy link
Contributor

pmario commented Mar 4, 2023

Will this make it possible, that we have predictable state-variables based on tiddler fields instead of needing to use "qualified states" which have unpredictable numbers?

@Jermolene
Copy link
Owner Author

Will this make it possible, that we have predictable state-variables based on tiddler fields instead of needing to use "qualified states" which have unpredictable numbers?

No.

What would that look like?

Those "unpredictable numbers" are because we hash long state qualifiers to make them easier to work with. There's no requirement to take that approach, but I don't think we have yet come up with an approach that is better while still being as general purpose.

@pmario

This comment was marked as off-topic.

@Jermolene
Copy link
Owner Author

Hi @pmario please could we move that question to a separate issue?

@Jermolene Jermolene merged commit a6ced74 into master May 6, 2023
1 check passed
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.

None yet

2 participants