Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    qbit
    @qbit:tapenet.org
    [m]
    i just learned about \import and transclusions..
    1 reply
    so excited
    qbit
    @qbit:tapenet.org
    [m]

    does anyone have an example of passing a macro a variable? I have it half working..

    <$set name="osName" value="{{!!name}}">
    <$macrocall $name="hardwareTable" filterField="os" filterValue="<<osName>>" />
    </$set>
    
    <<hardwareTable os OpenBSD>>

    The first macrocall shows the table but with no values in the table - the second shows the table but with values

    what's strange is that I can print the vars from inside the macro and they are set as expected in both cases
    the macro is:
    \define hardwareTable(filterField, filterValue, filterSort:"sort[cost]")
    
    showing "$filterField$" with value "$filterValue$"
    
    <table>
    <thead>
    <tr>
    <td> Name </td>
    <td> Usage </td>
    <td> Acquired </td>
    <td> Architecture </td>
    <td> Operating System </td>
    <td> Cost </td>
    </tr>
    </thead>
    <$list filter="[tag[Hardware]field:$filterField$[$filterValue$]$filterSort$]">
      <tr>
        <td> <$link/> </td>
        <td> {{!!usage}} </td>
        <td> {{!!purchased}} </td>
        <td> <$link to={{!!architecture}}>{{!!architecture}}</$link> </td>
        <td> <$link to={{!!os}}>{{!!os}}</$link> </td>
        <td align="right"> {{!!cost}} </td>
      </tr>
    </$list>
    </table>
    done showing "$filterField$" of "$filterValue$".
    \end
    the showing "$filterField$" with value "$filterValue$" lines show as expected in both calls to the macro
    also calling <<hardwareTable os {{!!name}}>> results in the same missing data-in-table issue
    1 reply
    qbit
    @qbit:tapenet.org
    [m]
    i think {{!!name}} is losing scope..
    @yanderella:sibnsk.net
    [m]

    Uh... Doing things a little in reverse than originally intended, because I just saw a glaring error using my TiddlyWiki experience.

    You are doing this as a way to pass external variable to the macro.

    filterValue="<<osName>>"

    That's not how things work, because of macro parameters being stupid simple string subtition and not magic. Essentially by passing this, you are telling the macro. "I want for filterValue to be the string (quotes) <<osName>>. You make filterValue to be exactly the characters <<osName>>, it's not magically going to resolve.

    However, TiddlyWiki has a way to pass a variable as a parameter, this looks like this.

    filterValue=<<osName>>

    Now this means, "I want filterValue to be the value of the variable osName"

    This will give you, your desired result. This is another reason why <<__osName__>> variable also exists, which would be for quote escaping problems.

    This is what your solution should be, so it ends here. Below this, is a small bonus of mine to explain something unrelated (initially thinking you need it) so feel free to ignore it as it is not part of your solution.


    By themselves, the snippets are not parsed as WikiText. However, a variable reference will transclude a snippet into a context where WikiText parsing may be occurring. Within a snippet, the only markup detected is $name$ for a macro parameter transclusion and $(name)$ for a variable transclusion.

    Source: https://tiddlywiki.com/#Variables

    Within a snippet itself, the only markup detected is $name$ (a placeholder for a macro parameter) and $(name)$ (a placeholder for a variable).

    Source: https://tiddlywiki.com/#Macros

    So I would like to present you with an example usage and how you can use these as part to control filters even better and hopefully that way you'll have even better control of things and "scope" understanding.

    \define greet_qbit(greeting)
    $greeting$, $(the_name)$
    <br/>
    <$text text={{{ [[$greeting$]addprefix[$(the_name)$, ]] }}} />
    \end
    
    <$vars the_name={{!!user}} >
    <$macrocall $name=greet_qbit greeting={{!!name}} />
    </$vars>

    Basically, $macroparametertransclusion$ this puts the parameter simply by replacing that placeholder string with the parameter value no other magic involved. $(variabletransclusion)$ this puts a variable defined outside the macro, but that the macro is "inside" of the variable definition. It does it again very simply by replacing the string with that variable value with no magic, just string substitution.


    Now, after you read my simpler explanation of variable transclusion within a macro vs macro parameters transclusion. You should be fully ready to read comfortably the source for macro definitions in WikiText.

    Source and further reading https://tiddlywiki.com/#Macro%20Definitions%20in%20WikiText

    qbit
    @qbit:tapenet.org
    [m]
    awesome - thanks for the explanation !
    switching to {{!!name}} fixed it - what was confusing to me is that it worked in some places but not in the table
    (my invalid setting of filterValue worked)
    @yanderella:sibnsk.net
    [m]
    I am glad that you fixed it! Good job!
    qbit
    @qbit:tapenet.org
    [m]

    Trying to add something similar to this: https://groktiddlywiki.com/read/#Creating%20a%20List%20of%20Links%20and%20Backlinks - I have a tiddler named $:/qbit/TiddlerLinkSummary with basically the template described in the "answers" section

    I have also added it to the list field in $:/tags/ViewTemplate, however, I don't see the templated stuff added to all tiddlers

    perhaps I need to use a different template for that?
    or maybe i am misunderstanding the entire point of $:/tags/ViewTemplate :D
    My goal is to have a list of backlinks and links shown on each tiddler
    @yanderella:sibnsk.net
    [m]

    I am in a rush so I didn't check anything in depth what you are trying to do, but long time ago I read something about ViewTemplate and backlinks. I happen to have the link saved since it seemed helpful. So have a look. It may help?

    https://old.reddit.com/r/TiddlyWiki5/comments/hm5n8n/looking_for_makro_that_will_show_all_relations_to/

    Good luck

    qbit
    @qbit:tapenet.org
    [m]
    Thanks! :D
    qbit
    @qbit:tapenet.org
    [m]
    yay! that had a bit that i was missing :D - needed to add the $:tags/ViewTemplate to my backlink tiddler as a literal tag
    @yanderella:sibnsk.net
    [m]

    Yes, that's how these are. They are core tags where the core has special functionality available that is built in and very useful. Same goes for some special field values like list-after and list-before.

    Not just that but there is an additional way to modify list field of a tag. That is by clicking on the tag pill on any tiddler. Then you get list of tiddlers tagged by that tag and you can drag them around to reorder them. Super convenient, I use this a lot myself. So go ahead and try this on the $:/tags/ViewTemplate tag pill on your template.

    qbit
    @qbit:tapenet.org
    [m]
    excellent :D - thanks again!
    bruno366
    @bruno366:matrix.org
    [m]
    Hello 👋 :)
    qbit
    @qbit:tapenet.org
    [m]
    Hi!
    bruno366
    @bruno366:matrix.org
    [m]
    Any idea how I might have one tiddler at the bottom of the story permanently? What I'm trying to do is have a sitemap at the bottom of the page, for example like this: https://www.atlassian.com/
    they have at the bottom links to PRODUCTS, RESOURCES, EXPAND & LEARN, ABOUT ATLASSIAN
    I was planning on doing this with a tiddler that links to other tiddlers (like a table of contents, but in a table-format)
    qbit
    @qbit:tapenet.org
    [m]
    bruno366: I did this recently :D thanks to the help of - can you see the chat history?
    basically you need to make a tiddler (i did a system tiddler named $:/qbit/TiddlerLinkSummary to reduce visual clutter) then tag that new tiddler with $:/tags/ViewTemplate
    there is more detail in the few messages above where you joined :D
    bruno366
    @bruno366:matrix.org
    [m]
    hmm... yes i can see the chat history, but i don't see anything related to what i'm trying todo, but i'll give it a try and get back to you :)
    ah ok, i get it now. your solution adds a text at the end of every tiddler. I just want at the end of the story, once, at the bottom of the page :)
    bruno366
    @bruno366:matrix.org
    [m]
    looking at $:/core/ui/PageTemplate/story I found $:/tags/BelowStory
    qbit
    @qbit:tapenet.org
    [m]
    ah, sorry - i misread
    i am not familiar with stories
    bruno366
    @bruno366:matrix.org
    [m]
    and it was what I wanted 🥳 yaaay :) thank you, your solution wasn't exactly what I wanted, but close enough that I was able to solve it 😄
    qbit
    @qbit:tapenet.org
    [m]
    is that a plugin?
    \o/
    bruno366
    @bruno366:matrix.org
    [m]
    nope no plugin, just like you used a tag to edit the viewTemplate, there apparently was a tag to edit pageTemplate, to put something belowStory which is what I wanted :D
    qbit
    @qbit:tapenet.org
    [m]
    neat
    qbit
    @qbit:tapenet.org
    [m]
    cool!
    qbit
    @qbit:tapenet.org
    [m]
    Does anyone know if it's possible to automatically add a set of feilds to a tiddler that you have transcluded?
    @yanderella:sibnsk.net
    [m]
    Depends on how you have transcluded it? If there is a way to access the name, should be? Can you give a wikitext example where you want to do that?
    qbit
    @qbit:tapenet.org
    [m]
    transcluded with {{||ThingAndStuff}} - I don't have a specific example - more curious
    my current workflow seems to be:
    • make a template with a table that displays a set of feilds
    • transclude said template
    • forget what fields i need to fill out
    • reference template :P
    i'd like to just skip the forget/reference step
    @yanderella:sibnsk.net
    [m]

    I am not sure what you mean exactly.... but that's because I cannot understand it. Anyway... I will try to give you something in hope that it may be what you want.

    Create a new tiddler and put this as contents...

    ''Info'': <$edit-text tiddler="$:/temp/test" field=testfield /> <br />
    ''Msg'': <$edit-text tiddler="$:/temp/test" field=testfield2 /> <br />
    <$button>
    <$action-setfield  info={{$:/temp/test!!testfield1}} />
    <$action-setfield  msg={{$:/temp/test!!testfield2}} />
    <$action-deletefield $tiddler="$:/temp/test" testfield testfield2/>
    Set fields  info and msg of current tiddler.
    </$button>

    and I guess the next time you forget what fields were there, you can just transclude this tiddler with something like {{||ThingsAndStuff}} then you'd be able to set whatever fields you had to set without having to remember anything else but one main field editing template?

    Sorry if that's not remotely related to your answer. I don't understand and probably won't be able to help you.

    qbit
    @qbit:tapenet.org
    [m]
    :D - i'll try it and see - either way it has things I can learn from, so thank you!! <3
    @yanderella:sibnsk.net
    [m]
    Also as a side thing about "forgetting and referencing the template". I actually try to write small "Help" tiddlers that document things briefly and put them in the sidebar (with the tabs macro), so that it is easy to reach and find out in the middle of editing without putting tiddlers in the story river. These "Help" tiddlers are pretty much my conventions used in the current TiddlyWiki. It's kinda tedious to update and maintain them as well as my templates but it pays off to not look up where my template is and the code used unless really needed after not opening it for too long. So I do recommend on thinking about conventions you want to use, write them in the TiddlyWiki as you have them and where in a tiddler and keep personal conventions as consistent as possible. Other than that, I haven't figured out a better way myself.