def render(template, scriptingContext): engine = getEngine() template, errors = engine.loadString(template, False) result, evaluation_errors = template.evaluate(scriptingContext) if evaluation_errors: from collective.templateengines.utils import dump_messages dump_messages(evaluation_errors) return result
def compile(self, text): """ Compile the template. """ engine = getEngine() if text == None: text = "" # TODO: Compile template only if the context has been changed t, messages = engine.loadString(text, False) return t, messages
def initialize(context): """Initializer called when used as a Zope 2 product.""" # Register additional easytemplat tags from tsv.policy.easytemplate.tags import TodayTag, SpieltermineTag, VereinstermineTag tags = [TodayTag(), SpieltermineTag(), VereinstermineTag()] from collective.easytemplate import tagconfig [tagconfig.tags.append(tag) for tag in tags] from collective.easytemplate.engine import getEngine, setupEngine from collective.templateengines.backends import jinja [getEngine().addTag(tag) for tag in tags] setupEngine(jinja.Engine())
def applyTemplate(context, string, logger=None): """ Shortcut to run a string through our template engine. @param context: ITemplateContext @param string: Template as string @return: tuple (output as plain text, boolean had errors flag) """ if logger: if string is not None: logger.debug("Applying template:" + string) else: logger.debug("Applying template:<empty string>") engine = getEngine() # TODO: Assume Plone template context - should be an explict parameter? request = context.getMappings()["context"].REQUEST if string == None: string = "" # We might have unicode input data which # will choke Cheetah/template engine string = string.encode("utf-8") errors=False # TODO: Compile template only if the context has been changed t, messages = engine.loadString(string, False) outputTemplateErrors(messages, request=request, logger=logger, context=context) errors |= len(messages) > 0 output, messages = t.evaluate(context) outputTemplateErrors(messages, request=request, logger=logger, context=context) errors |= len(messages) > 0 return output, errors
def test_00_assume_jinja(self): """ Only Jinja backend supports security. """ self.assertTrue(isinstance(engine.getEngine(), jinja.Engine))
from zope.i18nmessageid import MessageFactory easyslider_message_factory = MessageFactory('collective.easyslider') import logging logger = logging.getLogger('collective.easyslider') try: from collective.easytemplate.engine import getEngine from tags import SliderTag, SliderViewTag engine = getEngine() engine.addTag(SliderTag()) engine.addTag(SliderViewTag()) logger.info("Installed slider easytemplate tag") except: logger.info("easytemplate not installed. Can not install slider tag") def initialize(context): pass