Hey I'm wondering if its possible to create a passage that dynamically links to every passage with a certain tag. Like an index page that will update as I add passages
The Story.lookup function will return an array of all the passages that meet a set condition, the example shows using it to look for all passages with the "forest" tag.
If you combine that list with a <<for>> macro you should be able to create what you want.
note: I am not current at a machine with SugarCube 2 installed, so the following has not been tested.
<<set $list to Story.lookup("tags", "forest")>>
<<for $i to 0; $i lt $list.length; $i++>>
<<set $title to $list[$i].title>>
[[$title]]
<</for>>
Thanks! That seems to work great for populating the list but I'm seeing an issue with linking to actual passages. It autocreates a passage called $title and isn't interpreting the variable in the passage. I just get a number of broken links that all display $title
However if I do <<print $title>> it does correctly show the variable value, lthough not as a link of course
EDIT It looks like it works if i use <a data-passage=$title>$title</a> and publish to a file. It seems the error is coming from Twine's test browser.
Currently Twine 2 features like Auto Passage Creation and Broken Link Detection and Passage Map Connections only understands basic markup links like the following:
So when you use advanced markup links (like ones containing $variables) or macro based links strange things happen like incorrectly named auto-created passages. Generally you can delete these passages.
Comments
If you combine that list with a <<for>> macro you should be able to create what you want.
note: I am not current at a machine with SugarCube 2 installed, so the following has not been tested.
However if I do <<print $title>> it does correctly show the variable value, lthough not as a link of course
EDIT It looks like it works if i use <a data-passage=$title>$title</a> and publish to a file. It seems the error is coming from Twine's test browser.
I did say my example was untested *smile*
Or, for a JavaScript-style solution, this:
Both of which should bypass Twine 2's less than ideal link handling.