can i add javascript to a page generated with yattag?
sandrotosi opened this issue · 4 comments
Hello,
i want to add a small javascript snippet to the page i generate with yattag, but it's unclear if yattag supports that at all
Can i do that? if so, how?
thanks!!
Hello,
sorry for the late reply to this question.
Yes, it's possible but there's not really something specific to Yattag here. Just generate a correct HTML document containing a <script>
tag and that will work.
The following code does not generate a script
tag for me
with tag('html'):
with tag('head'):
doc.tag('script', src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js')
The above code generates
<html>
<head></head>
</html>
Use doc.stag
instead of doc.tag
.
stag
is used to generate a self closing tag. That's probably what you want here.
tag
is used to open a tag and you need to use the with
keyword with it (with tag(...): ...
)
stag
generates <script />
but <script></script>
is what is really needed.