Reputation: 107
I am looking to generate a string like \usepackage{mypackage}
from a Django template.
Suppose there is a variable package.name
in the context how can I generate this?
Firstly I tried, \usepackage{{{package.name}}}
but that throws TemplateSyntaxError
Then I tried \usepackage{ {{package.name}} }
which works but has the two spaces in the output, ie, \usepackage{ mypackage }
Is there an easy way to generate this string with Django template engine?
Upvotes: 1
Views: 1149
Reputation: 10577
You can also print strings with the mustache-syntax e.g.: {{ 'random string' }}
. So we can print the corresponding curly brace like this:
\usepackage{{ '{' }}{{ package.name }}{{ '}' }}
Output:
\usepackage{mypackage}
Upvotes: 2
Reputation: 111
one option is that you can write a template tag that will render it as you want and give the package name as a variable
Upvotes: 0
Reputation: 691
You can do something like this using span
\usepackage{<span>{{package.name}}</span>}
Upvotes: 0