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

roll template output formatting based on an attribute

1526153252
vÍnce
Pro
Sheet Author
Generally, I have no problem formatting roll templates with css, but I want to change the formatting on a div used within a roll template based on an input/checkbox that's located on the sheet. I tried including a hidden input within the roll template to be used as a trigger, but I think the way roll templates are designed, inputs get sanitized.  Is this possible? Anyone done this on their sheet?  TIA
1526154479
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
What's the inputs possible values?
1526156173
Jakob
Sheet Author
API Scripter
Vince said: Generally, I have no problem formatting roll templates with css, but I want to change the formatting on a div used within a roll template based on an input/checkbox that's located on the sheet. I tried including a hidden input within the roll template to be used as a trigger, but I think the way roll templates are designed, inputs get sanitized.  Is this possible? Anyone done this on their sheet?  TIA You'll want to include a flag like {{show_foo=1}} or {{show_bar=1}} and set that as the value of an attribute that you include on the roll template. Then you can use the helper functions to change the formatting. You can even use (simple) helper functions in the value of the class attribute: <div class="bar{{#show_foo}} foo{{/show_foo}}">
1526157819
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Jakob said: ...You can even use (simple) helper functions in the value of the class attribute: <div class="bar{{#show_foo}} foo{{/show_foo}}"> What's the benefit of doing this Jakob?
1526159224
Jakob
Sheet Author
API Scripter
You can conditionally add a class to the roll template to influence formatting (like setting a different background, changing fonts, etc). I have a {{korean=1}} flag for the Blades sheet that modifies the roll template fonts to work better for Korean. I also have a {{short=1}} flag that modifies the height of the template. Both are implemented in the above way.
1526163955
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
So, the class changes to be whatever the result of the template field test is?
1526169865
vÍnce
Pro
Sheet Author
I'll have to try this out.  Use case; I added vertical scrolling on the div used around {{description=}} so that long text gets a scroll bar after a fixed height instead of taking up three pages of chat.  Some people prefer to have all the text displayed without having to scroll within the description.  So, I'm trying to add an option in the sheet's settings that would toggle scrolling within the description key.
1526181744
vÍnce
Pro
Sheet Author
I was able to get this to work in my tests with your suggestions/examples.  I wasn't sure exactly how to implement this using a flag ie {{scroll_desc=1}} so I simply added {{scroll_desc=@{scroll-desc}}} in the sheet's macros.  @{scroll-desc} is an input selector from the sheet's settings page with options; 1."scroll-desc" ("sheet-" is automatically added by roll20) or 2."& nbsp;"   I added css to match "sheet-scroll-desc" for the intended scroll-ability when using option 1. from above. I included a simple helper for {{scroll_desc}} within the roll template's div as per Jakob's tip above.  <div class="{{#scroll_desc}}{{scroll_desc}}{{/scroll_desc}}"... Seems to work as intended.  Thanks for the help.
1526182187
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
That's cool.
1526192321
Jakob
Sheet Author
API Scripter
Glad it works!
1526214643

Edited 1526217767
Natha
KS Backer
Sheet Author
API Scripter
If your attribute has a fixed number of values (let's say A or B), you don't even need the helper function. In the roll template: <div class="sheet-myclass{{mychoice}}"> (some stuff) </div> In your CSS: .sheet-rolltemplate-mytemplate .sheet-myclassA {     (some stuff) } .sheet-rolltemplate-mytemplate .sheet-myclassB {     (other stuff) }
1526216516
Jakob
Sheet Author
API Scripter
Duh, that's much easier and works just as well, Natha!
1526217511
Natha
KS Backer
Sheet Author
API Scripter
Glad to help :) That trick made my life simpler from time to time ;)
1526221090
vÍnce
Pro
Sheet Author
Natha said: If your attribute has a fixed number of values (let's say A or B), you don't even need the helper function. In the roll template: <div class="sheet-myclass{{mychoice}}"> (some stuff) </div> In your CSS: .sheet-rolltemplate-mytemplate .sheet-myclassA {     (some stuff) } .sheet-rolltemplate-mytemplate .sheet-myclassB {     (other stuff) } I suppose wrapping with helpers {{#foo}}{{foo}}{{/foo}} are only needed for displaying IF something is present? That's slick.  Thanks
1526222369

Edited 1526222716
Natha
KS Backer
Sheet Author
API Scripter
Vince said: I suppose wrapping with helpers {{#foo}}{{foo}}{{/foo}} are only needed for displaying IF something is present? Never tried but if {{foo}} is present in the roll, but empty, it should also work, either if foo contains a full CSS class name, like <div class="baseclass {{foo}}"> CSS: .sheet-rolltemplate-mytemplate .sheet-baseclass {     (some stuff) } .sheet-rolltemplate-mytemplate .sheet-baseclass.sheet-WithFooValue {     (other stuff) } Or part of a class name: <div class="baseclass{{foo}}"> CSS: .sheet-rolltemplate-mytemplate .sheet-baseclass {     (some stuff) } .sheet-rolltemplate-mytemplate .sheet-baseclassWithFooValue {     (other stuff) }
1526222546
Natha
KS Backer
Sheet Author
API Scripter
EDIT : sorry had to edit 3 times to set it right, above ...
1526222587
vÍnce
Pro
Sheet Author
I'm going to update my code.  Thanks
1526222818

Edited 1526222839
Natha
KS Backer
Sheet Author
API Scripter
Sorry, had an extra space in the full class name example above. Fixed.