How to use the twig.renderFile function in twig

To help you get started, we’ve selected a few twig examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dpc-sdp / ripple / scripts / generate-readme / generate-readme.js View on Github external
let storiesOfMatch = storiesOf.exec(story)

  let add = /(?:add\([\n\s]*)(?:')(.+)(?:',)/gim
  let addMatch = add.exec(story)
  while (addMatch !== null) {
    data.storybookParams.push({
      path: 'Storybook/' + addMatch[1].replace('\\', ''),
      params: '?selectedKind=' + encodeURI(storiesOfMatch[1]) + '&selectedStory=' + encodeURI(addMatch[1])
    })
    addMatch = add.exec(story)
  }

  // Add check for no-ssr folder.

  // Render template.
  Twig.renderFile(path.join(__dirname, '/README_template.md'), data, (err, html) => {
    if (err) {
      console.log(err)
    } else {
      // Strip comments & write.
      html = html.replace(/\n/gi, '')
      fs.writeFileSync(directory + 'README.md', html)
    }
  })
}
github codex-team / hawk / hawk / routes / yard / websites.js View on Github external
logger.info('Register new domain: ' + domain);

            if (process.env.ENVIRONMENT == 'DEVELOPMENT') {

              console.log('Domain: ', domain);
              console.log('Token: ', token);

            } else {

              let renderParams = {
                domain: domain,
                token: token,
                serverUrl: process.env.SERVER_URL
              };

              Twig.renderFile('views/notifies/email/domain.twig', renderParams, function (err, html) {

                if (err) {

                  logger.error('Can not render notify template because of ', err);
                  return;

                }

                email.init();
                email.send(
                  res.locals.user.email,
                  'Integration token for ' + domain,
                  '',
                  html
                );
github dpc-sdp / ripple / src / scripts / generate-component / generate-component.js View on Github external
files.forEach((item) => {
  Twig.renderFile(path.join(__dirname, item.template), data, (err, twigOutput) => {
    if (err) {
      console.log(err)
    } else {
      fs.writeFileSync(directory + item.output, twigOutput)
    }
  })
})
github codex-team / hawk / hawk / routes / yard / auth / join.js View on Github external
.then(function ({insertedUser, password}) {
              if (insertedUser) {
                if (process.env.ENVIRONMENT == 'DEVELOPMENT') {
                  console.log('Your email: ', insertedUser.email);
                  console.log('Your password: ', password);
                } else {
                  let renderParams = {
                    password: password,
                    settingsLink: process.env.SERVER_URL + '/garage/settings'
                  };

                  Twig.renderFile('views/notifies/email/join.twig', renderParams, function (err, html) {
                    if (err) {
                      logger.error('Can not render notify template because of ', err);
                      global.catchException(err);
                      return;
                    }

                    email.send(
                      insertedUser.email,
                      'Welcome to Hawk.so',
                      '',
                      html
                    );
                  });
                }

                res.redirect('/login?success=1&email=' + insertedUser.email);
github codex-team / hawk / hawk / routes / garage / project.js View on Github external
.then(function (insertedProject) {
        let renderParams = {
          name: insertedProject.name,
          token: insertedProject.token,
          serverUrl: process.env.SERVER_URL
        };

        Twig.renderFile('views/notifies/email/project.twig', renderParams, function (err, html) {
          if (err) {
            logger.error('Can not render notify template because of ', err);
            global.catchException(err);
            return;
          }

          email.send(
            res.locals.user.email,
            'Integration token for ' + insertedProject.name,
            '',
            html
          );
        });

        let message = insertedProject.name + ' was successfully added';
github igorzg / js_cms / src / components / template-engine.ts View on Github external
return new Promise((resolve, reject) => {
      let templatePath = TemplateEngine.getTemplatePath(template, path);
      this.logger.debug("Loading template path", {templatePath, data})
      try {
        renderFile(
          templatePath,
          data,
          (error, html) => {
            if (error) {
              reject(error);
            } else {
              resolve(html);
            }
          }
        );
      } catch (e) {
        reject(e);
      }
    });
  }
github codex-team / hawk / hawk / models / notifies.js View on Github external
users.forEach(function (userData) {
          let userId = userData.userId.toString(),
            renderParams = {
              event: event,
              project: project,
              serverUrl: process.env.SERVER_URL,
              times: times,
              userData: userData,
              unsubscribeHash: generateUnsubscribeHash(userId, project._id)
            };


          Twig.renderFile(templatesPath + templates.messenger, renderParams, function (err, html) {
            if (err) {
              logger.error('Can not render notify template because of ', err);
              return;
            }

            /**
             * Send Telegram notification
             */
            if (userData.notifies.tg && userData.tgHook) {
              request.post({
                url: userData.tgHook,
                form: {
                  message: html,
                  parse_mode: 'HTML'
                }
              }, (err, httpResponse, body) => {
github codex-team / hawk / hawk / routes / garage / project.js View on Github external
let newMemberRequest = await project.addMember(foundProject._id, null, null, userEmail);

    let inviteHash = project.generateInviteHash(newMemberRequest.insertedId, foundProject._id);

    let inviteLink = process.env.SERVER_URL + '/invite'
      + '?member=' + newMemberRequest.insertedId
      + '&project=' + foundProject._id
      + '&hash=' + inviteHash;

    let renderParams = {
      project: foundProject,
      inviteLink: inviteLink
    };

    Twig.renderFile('views/notifies/email/projectInvite.twig', renderParams, (err, html) => {
      if (err) {
        logger.error('Error while rendering email template %o' % err);
        global.catchException(err);
        return;
      }

      email.send(userEmail, 'Invitation to ' + foundProject.name, '', html);
    });

    res.json({
      success: 1,
      message: 'Invitation for ' + userEmail + ' was sent'
    });
  } catch (e) {
    logger.error('Error while sending project invitation ', e);
    global.catchException(e);