I am having a hard time with an optional tal attribute.
<tal:block define="y_width options/youtube_width | nothing;">
<div width="437" tal:attributes="width y_width | string:600;"></div>
</tal:block>
I want to keep it so that if the user doesn’t enter any options in the width value it will default to 437. I thought I could change the “or nothing” operator in the define block but that doesn’t work. Above is another thing I tried out putting the or after the attribute but in either case the code justs go away. How can I make it so that if the user input values are empty, the code defaults to certain values?
You’ll have to use a python expression here, as the
|pipe operator only kicks in onAttributeErrororKeyError, but in your case “y_width” will beNone: