Allow for hidden template within page.
buckett opened this issue · 4 comments
As well as allowing the template to be in a different file it would be useful if the template could be pulled from the current page. This way the page is self contained and the single file can be copied around.
There's the <template>
tag https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template which might be a good fit. I'm not sure how it would be best to handle the attributes on the tag though?
<codapi-snippet sandbox="python" editor="basic" template-uri="warpper.py">
and
<template id="python-template">
print("started")
###CODE###
print("finished")
</template>
<codapi-snippet sandbox="python" editor="basic" template-selector="#python-template">
or it it's better to just have the template
attribute first try to see if the supplied string works as a selector before making a fetch()
call?
Thanks for the suggestion! I need some time to think about it 🤔
Maybe follow the pattern of finding the closest <template>
and using that if nothing is specified?
As of 0.3.0, you can use an in-page script
tag with a code template and pass its id
as a template
:
<script id="main.py" type="text/plain">
def main():
##CODE##
</script>
<pre>
print("Hello, World!")
</pre>
<codapi-snippet sandbox="python" template="#main.py"></codapi-snippet>
The leading #
in template
and type="text/plain"
in script
are required.