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

Translink should default to currentTiddler, use cascade for block mode, detect simple recursion #8834

Open
springerspandrel opened this issue Dec 20, 2024 · 1 comment

Comments

@springerspandrel
Copy link
Contributor

Is your feature request related to a problem? Please describe.

The translink macro is exactly what's needed for many uses, but the shorthand <<translink>> doesn't conveniently work within list or tiddler widgets, because it fails to default to currentTiddler.

A second inconvenience is that translink, up until now, has not harnessed the cascade for display of the tiddler's body (in block mode).

(I do see that transclude, in general, does not do so. In my view, transclude has so many other purposes woven into the core, and it might create problems if transclude were modified so as to attempt, even in block mode, to harness the cascade. Translink, by contrast, is much more appropriate for cases where the intent is: "here's a framed copy of that tiddler, title and all".)

Describe the solution you'd like

I've written a workable replacement that has both of these features, plus recursive transclusion detection:

  • It can be invoked simply as <<translink>> within list widgets (etc.) defaulting to the currentTiddler.
  • It uses the cascade for block mode, as defined through $:/tags/ViewTemplateBodyFilter
  • It also triggers a "recursive transclusion" error if <<translink>> is accidentally invoked "raw", or otherwise ends up with its title parameter matching the storyTiddler enclosing it.

Describe alternatives you've considered

I can create long-form workarounds to behave as needed. But since most other macros and widgets allow a default to currentTiddler, this seems much more elegant and in keeping with user expectations.

Additional context

Below is a workable version of code which I propose as future contents of

$:/core/macros/translink

\define translink(title,mode)
\whitespace trim

<$parameters title={{{ [<__title__>!is[blank]else<currentTiddler>] }}} mode={{{ [<__mode__>!is[blank]else[block]] }}}>

<%if [<title>match<storyTiddler>]  %>
<span class="tc-error">{{$:/language/Error/RecursiveTransclusion}}</span>
<% else %>

<$tiddler tiddler=<<title>> >

<%if [<__mode__>!match[inline]] %>

<div class="tc-translink">
<h1><$link/></h1>
{{||$:/core/ui/ViewTemplate/body}}
</div>

<%else%>

<span class="tc-translink">
<$link/> &#32;(<$transclude mode="inline">
<$transclude tiddler="$:/language/MissingTiddler/Hint"/> </$transclude>)
</span>

<% endif %>
</$tiddler>
<% endif %>
</$parameters>
\end
@Jermolene
Copy link
Member

Hi @springerspandrel these seem like worthwhile improvements. Are there any backwards compatibility implications?

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

No branches or pull requests

2 participants