I'm trying to define a variable in python and have that be used in my Jinja template. My understanding is that this needs to (somehow) get from Python into the Jinja context, but as Octoprint is ultimately making the render call I'm not quite sure how to do this correctly.
I naively tried putting:
myVar = "Hello World"
in init .py and then putting
<span>{{myVar}}</span>
but to no avail. I'm sure I'm just being dumb!
I believe this is the section of the docs you are looking for (direct link):
https://docs.octoprint.org/en/master/plugins/mixins.html#octoprint.plugin.TemplatePlugin.get_template_vars
Use get_template_vars
and return a dict of values, then they can be referenced using the prefix plugin_<plugin id>_
Examples:
https://github.com/cp2004/OctoPrint-EEPROM-Marlin/blob/a0b6d1f92740da1233f8049107c13e9d8c1d5547/octoprint_eeprom_marlin/init .py#L103-L105
<p>Enjoying the plugin? <strong>Support it's development!</strong> I work on all of my plugins in my spare time, if you think this was worth it please consider supporting my work below:</p> <a class="btn btn-success" href="https://github.com/sponsors/cp2004/" target="_blank"><i class="fa fa-heart" aria-hidden="true"></i> Support the plugin</a> <button class="btn btn-success" data-toggle="modal" data-target="#EEPROMSponsorsModal">View Sponsors</button> <button class="btn btn-primary" data-toggle="modal" data-target="#EEPROMContributorModal">View Contributors</button> <!-- Footer --> <div> <hr> <p> Marlin EEPROM Editor by <a href="https:github.com/cp2004">Charlie Powell</a> | <i class="fa fa-tag text-success"></i> Version {{ plugin_eeprom_marlin_version }} - <a href="https://github.com/cp2004/OctoPrint-EEPROM-Marlin/releases" target="_blank">Release Notes</a> </p> </div> <!-- Sponsors & Contributor modals --> {% include "sponsors-contributors.jinja2" %}
1 Like
Perfect! I figured it would be buried in there somewhere! Thanks