I just tried to create a form with a single checkbox and an inline help_text next to it, like this:
[x] This is the help_text
As I understood bootstrap_toolkit a tried the following:
{{ my_form.thefield|as_bootstrap:'inline' }}
However, this didn't work like I expected, instead I got this result:
[x]
This is the help_text
Getting curious, I look in the source for field_inline.html
and saw {% include "bootstrap_toolkit/field_help.html" with inline=True %}
and in the field_help.html
template I found the {% if inline %}
condition with an <span class="help-inline">
in the body of it. Checking with the bootstrap documentation this is the correct class for an inline help_text directly next to a field. Putting some additional text within the true- and false-branch of the condition I discovered that, the true-branch is never run.
At first, this made no sense to me. After all, the template is included with inline=True
so inline should be true, or shouldn't it? As it turns out, no! Turns out that True
is not a literal in the Django template syntax. Instead True
is resolved as a variable for the current context where it (most likely) doesn't exist so TEMPLATE_STRING_IF_INVALID is outputted. TEMPLATE_STRING_IF_INVALID in turn defaults to an empty string and an empty string is false. So even if you pass inline=True
inline is actually false.
In short: It's currently not possible to format fields with 'help-inline' class because the code is not reachable.