Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Trying to put character's token on roll template

1641115213

Edited 1641115287
StéphaneD
Pro
Sheet Author
API Scripter
Hi For a character sheet I'm authoring, I'd like to include the character's token on the roll templates used by the sheet. Here is what I've done : Added some code to the "on:opened" event of the sheet worker script and grabbed the character_token pseudo attribute and saved it as a new token_url attribute, stripping the leading https and trailing .png?xxxx Added a new {{token=@{token_url} }} to the macro of a roll button Changed the roll template to include an img element with a src="https://{{token}}.png" attribute I can see that the token_url attribute has been correctly created However in the chat, the image is not displayed, because the {{token}} substitution did not happen, contrary to what is explained on [this page]( <a href="https://wiki.roll20.net/Image_use_in_character_sheets" rel="nofollow">https://wiki.roll20.net/Image_use_in_character_sheets</a> ) at the 'Dynamic Image in Roll Templates' paragraph What am I doing wrong ? Or is that some Roll20 known issue new unexpected feature ? TIA for any idea / insight Regards
1641141522
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You'll need to share your code for any useful help. But here's some thoughts: Why are you stripping out the https at the start? You just have to add it back in anyways. Similar question for removing the .png?xxxx at the end. I'd go about this by just doing a regex replace that removed the ?xxx at the end and call it good. I've done this on some test sheets and know of at least one other author that has done it, so I'm fairly certain there's a bug in your code.
1641143015
StéphaneD
Pro
Sheet Author
API Scripter
Hi Scott Thanks for the reply I think I have shared any useful code there is to share -- you don't need the code in the sheetworker as I mentioned that the attribute with the URL is correctly created. I'm stripping some data of the URL and re-adding it later, because if I load the full URL in the token_url attribute and then define the src property as src="{{token}}", then for some reason the whole src property is removed by Roll20 from the img element. I am not doing any DOM change, so I'm fairly certain Roll20 is not bug free in this instance. On the wiki page I mentioned, the {{xxx}} represents only a part of the full URL, so I figured out that was what I need to do. And it actually works a bit better than my first attempt (where Roll20 removes the src= from the img element), since it keeps the src= and uses the Roll20 image server proxy, excepted it does not substitute the {{xxx}} with the value passed in. If I type @{name of character|token_url} in the chat, the correct URL value created by the sheetworker is returned. If you know of someone who already did something similar, then can you please point me to their Github repo so that I can see if it is the same use case and if so, how they did it ? It would also be a good idea to check with them and see if it still works -- I've recently seen some of my code that had been working for years not working anymore without any change from my part, due to Roll20 infrastructure changes... TIA
1641150928
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Ah, went back and found where I had played around with it. I used the markdown image element format. So, like so: &lt;input type='text' name='attr_token' value=''&gt; &lt;rolltemplate class="sheet-rolltemplate-image"&gt; &nbsp; &nbsp; [Token]({{token}}) &lt;/rolltemplate&gt; And called like so: &amp;{template:image} {{token=<a href="https://s3.amazonaws.com/files.d20.io/marketplace/1128420/W2r85zkKX_UKmlpSSB7Pzw/original.jpg" rel="nofollow">https://s3.amazonaws.com/files.d20.io/marketplace/1128420/W2r85zkKX_UKmlpSSB7Pzw/original.jpg</a>}}
1641153085

Edited 1641153109
StéphaneD
Pro
Sheet Author
API Scripter
Scott Thanks but that does not work for me I have placed the [Token]({{token}}) inside a th element (as my roll template uses a table to display the data) It creates an hyperlink that points to the image's URL, but it does not display the image itself, which is the intended result... That being said, I'm missing the CSS code for the&nbsp; sheet-rolltemplate-image&nbsp; class&nbsp;
1641155810
Finderski
Pro
Sheet Author
Compendium Curator
It's a little tricky...I had to take the character_token and put it into a separate variable using a sheet worker... on("sheet:opened change:character_name change:character_avatar change:character_token", function() { getAttrs(["character_name","character_avatar","character_token"], function(v) { let name = v.character_name; let namelen = name.length; let nameclass; namelen &gt;= 19 ? (nameclass = "smallHeader") : (nameclass = "normalHeader"); setAttrs({ namelength: nameclass, "avatar": v.character_avatar, "ctoken": v.character_token }); }); }); Then I use ctoken in the roll template by using this: {{token=[x](@{ctoken}) }} That gives me something like this:
1641156240

Edited 1641156289
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
StéphaneD said: Scott Thanks but that does not work for me I have placed the [Token]({{token}}) inside a th element (as my roll template uses a table to display the data) It creates an hyperlink that points to the image's URL, but it does not display the image itself, which is the intended result... That being said, I'm missing the CSS code for the&nbsp; sheet-rolltemplate-image&nbsp; class When using the hyperlink method which is what both Finderski and myself use, the image must end in an image type (jpg,png, or gif). You can also force this by appending a tag to the url like <a href="http://www.myimage.org/1234#jpg" rel="nofollow">www.myimage.org/1234#jpg</a> . Also, there's no css for my demo rolltemplate. It's just raw html.
1641157868
vÍnce
Pro
Sheet Author
That's a nice looking template Finderski! +1
1641162302

Edited 1641162318
Finderski
Pro
Sheet Author
Compendium Curator
vÍnce said: That's a nice looking template Finderski! +1 Thanks. :) It's not in Prod, yet...LOL
1641204630

Edited 1641204777
StéphaneD
Pro
Sheet Author
API Scripter
Hey guys Less spectacular than Finderski nice looking roll template, but with your help and advices, it now works : Thanks all ! Best regards
1641207341
vÍnce
Pro
Sheet Author
Nice.&nbsp; I might borrow this idea as well. ;-)