0 votes
by (150 points)
I want to be able to avoid hard-coding the pathnames of images, so that I can get an exported story which uses offline images just by tweaking a single variable, without having to manually edit all the pathnames.  Has anyone done this?  I guess you have to build up the <img src=...> in a String, and (replace:) it in the text, but everything has failed so far.

1 Answer

+1 vote
by (159k points)

There are a number of ways to do this but one of the simplest is to create a story variable (like $host) within your startup tagged special passage, and then use the (print:) macro to dynamically create your img element using the story variable as part of the image's URL.

1a. The startup tagged special passage content used to access images via (Path) Relative URL.

(set: $host to "")

1b. The startup tagged special passage content used to access images via Full Path URL.

(set: $host to "http://hostname.com/")

2. The (print:) macro used to dynamically generate an image element.

(print: '<img src="' + $host + 'images/some-image.jpg">')

 

by (150 points)

Thanks -- that's a lot simpler than what I was trying to do.

...