Package com.hubspot.jinjava.lib.tag
Class ImportTag
- java.lang.Object
-
- com.hubspot.jinjava.lib.tag.ImportTag
-
- All Implemented Interfaces:
Importable
,Tag
,Serializable
public class ImportTag extends Object implements Tag
Jinja2 supports putting often used code into macros. These macros can go into different templates and get imported from there. This works similar to the import statements in Python. It’s important to know that imports are cached and imported templates don’t have access to the current template variables, just the globals by default.- Author:
- jstehler
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ImportTag()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Map<String,Object>
getChildBindingsWithoutImportResourcePath(Map<String,Object> childBindings)
static String
getContextVar(List<String> helper)
String
getEndTagName()
static List<String>
getHelpers(TagToken tagToken)
String
getName()
static Optional<String>
getTemplateFile(List<String> helper, TagToken tagToken, JinjavaInterpreter interpreter)
static void
handleDeferredNodesDuringImport(Node node, String contextVar, Map<String,Object> childBindings, JinjavaInterpreter child, JinjavaInterpreter interpreter)
static void
integrateChild(String contextVar, Map<String,Object> childBindings, JinjavaInterpreter child, JinjavaInterpreter parent)
String
interpret(TagNode tagNode, JinjavaInterpreter interpreter)
static Node
parseTemplateAsNode(JinjavaInterpreter interpreter, String templateFile)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.hubspot.jinjava.lib.tag.Tag
interpretOutput, isRenderedInValidationMode
-
-
-
-
Field Detail
-
TAG_NAME
public static final String TAG_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
public String getName()
- Specified by:
getName
in interfaceImportable
-
interpret
public String interpret(TagNode tagNode, JinjavaInterpreter interpreter)
-
integrateChild
public static void integrateChild(String contextVar, Map<String,Object> childBindings, JinjavaInterpreter child, JinjavaInterpreter parent)
-
getChildBindingsWithoutImportResourcePath
public static Map<String,Object> getChildBindingsWithoutImportResourcePath(Map<String,Object> childBindings)
-
handleDeferredNodesDuringImport
public static void handleDeferredNodesDuringImport(Node node, String contextVar, Map<String,Object> childBindings, JinjavaInterpreter child, JinjavaInterpreter interpreter)
-
parseTemplateAsNode
public static Node parseTemplateAsNode(JinjavaInterpreter interpreter, String templateFile) throws IOException
- Throws:
IOException
-
getTemplateFile
public static Optional<String> getTemplateFile(List<String> helper, TagToken tagToken, JinjavaInterpreter interpreter)
-
getEndTagName
public String getEndTagName()
- Specified by:
getEndTagName
in interfaceTag
- Returns:
- Get name of end tag (lowerCase). Null if it's a single tag without content.
-
-