Last updated: 10 Mar 18 16:47:15 (UTC)
Creating an index of passages - Twine
[Sugarcube 2] List of all passages with tag
October 2015 in Help! with 2.0
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
Comments
[](https://twinery.org/forum/profile/greyelf)[greyelf](https://twinery.org/forum/profile/greyelf)
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 <
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]] <>
[](https://twinery.org/forum/profile/ijohnston)[ijohnston](https://twinery.org/forum/profile/ijohnston)
October 2015 edited October 2015
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 $title and publish to a file. It seems the error is coming from Twine’s test browser.
[](https://twinery.org/forum/profile/greyelf)[greyelf](https://twinery.org/forum/profile/greyelf)
October 2015 edited October 2015
Currently Twine 2 features like Auto Passage Creation and Broken Link Detection and Passage Map Connections only understands basic markup links like the following:
[[Target Passage Name]] [[Link Text|Target Passage Name]] [[Link Text->Target Passage Name]] [[Target Passage Name<-Link Text]]
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.
I did say my example was untested smile
[(L)](https://twinery.org/forum/profile/TheMadExile)[TheMadExile](https://twinery.org/forum/profile/TheMadExile)
As a workaround, you could do something like the following:
<<set $list to Story.lookup(“tags”, “forest”)>>
<<for $i to 0; $i lt list.length; ++i>>
<<print “[” + “[” + list[i].title + “]” + “]”>>
<>
<<unset $list, $i>>
Or, for a JavaScript-style solution, this: <<print Story .lookup(“tags”, “forest”) .map(function (passage) { return “[” + “[” + passage.title + “]” + “]”; }) .join(“\n”)
Both of which should bypass Twine 2’s less than ideal link handling.