Using the query string to carry extra instructions

That would not be difficult to parse as long as you can be confident that the characters & and = will never appear in any of the values for these properties.

Assuming the custom startup module calls the actions with the raw hash string set as the variable url-hash:

<$list filter="[<url-hash>split[&]]" variable="pair">
	<$let key={{{ [<pair>split[=]first[]] }}} value={{{ [<pair>split[=]last[]] }}}
		<$action-setfield $tiddler=`$:/temp/moodle-data/$(key)$` text=<<value>> />
	</$let>
</$list>

Which for subdomain.tiddlyhost.com/##moodleid=55555&univid=666666&firstname=StudentName would give you the tiddlers:

title text field
$:/temp/moodle-data/moodleid 55555
$:/temp/moodle-data/univid 666666
$:/temp/moodle-data/firstname StudentName
1 Like

startup module tiddler with type application/javascript and module-type startup

/*\
title: $:/springer/url-hash-capture-startup.js
type: application/javascript
module-type: startup

Decode the URL hash and invoke custom actions on it
\*/

exports.name = "custom-startup";
exports.platforms = ["browser"];
exports.after = ["startup"];
exports.synchronous = true;

exports.startup = function(){

	var decodedHash = "";

	try {
		if(document.location.hash) {
			decodedHash = decodeURIComponent(document.location.hash.substring(1));
		}
	} catch(e) {
		// If decoding fails, fall back to raw hash
		decodedHash = document.location.hash ? document.location.hash.substring(1) : null;
	}
	if(decodedHash && decodedHash.charAt(0) === "#") {
		$tw.rootWidget.invokeActionsByTag("$:/tags/CustomStartupAction",null,{"url-hash":decodedHash.slice(1)});
	}
};

wikitext actions tiddler with tag $:/tags/CustomStartupAction

<$list filter="[<url-hash>split[&]]" variable="pair">
	<$let key={{{ [<pair>split[=]first[]] }}} value={{{ [<pair>split[=]last[]] }}} >
		<$action-setfield $tiddler=`$:/temp/moodle-data/$(key)$` text=<<value>> />
	</$let>
</$list>

Test with a URL like: subdomain.tiddlyhost.com/##moodleid=55555&univid=666666&firstname=StudentName

1 Like

Cool! I have quite a bit to do before I can really test this.

But it looks very promising, and much less of a headache to troubleshoot for the startup (and even easier to read the url visually, compared to squinting through the %20 spacers) compared to my prior system.

You’re the best, Saq!

1 Like

And, it was very quick to do a first proof-of-concept test! The startup action — to set temp tiddler values according to the url fragment’s key-value pairs — is working transparently.

In real-world use (within the university LMS iframes) there may be further hiccups, but I’m greatly reassured that this semester’s system will be cleaner-running and less awkward to manage.

1 Like

I was able to demonstrate that it was possible and eventually to create some wikitext versions of what I’d done in JS, but when I tried to submit a PR, the core team decided that they wanted to go the route of the issue Saq mentioned. While we tried to tease out requirements on that, the issue stalled, and I didn’t have the technical knowledge to try it without more guidance. I will probably look to how that might be done post 5.4.0. If we do manage to do that, then it should make the sorts of things you’re trying to do much easier, but it won’t be in time for your new semester, I’m afraid.

2 Likes