🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

egg-view-twig-x

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-view-twig-x

egg view plugin for twig

latest
Source
npmnpm
Version
0.0.2
Version published
Weekly downloads
3
-50%
Maintainers
1
Weekly downloads
 
Created
Source

egg-view-twig

NPM version build status Test coverage David deps Known Vulnerabilities npm download

egg view plugin for twig.

Install

$ npm i egg-view-twig --save

Usage

// {app_root}/config/plugin.js
exports.twig = {
  enable: true,
  package: 'egg-view-twig',
};

// {app_root}/config/config.default.js
exports.view = {
  mapping: {
    '.twig': 'twig',
  },
};

// twig config
exports.twig = {};

Create a twig file

// app/view/hello.twig
hello {{ data }}

Render it

// app/controller/render.js
exports.twig = function* () {
  yield ctx.render('hello.twig', {
    data: 'world',
  });
};

The file will be compiled and cached, you can change config.twig.cache = false to disable cache, it's disable in local env by default.

Include

You can include both relative and absolute file.

Relative file is resolve from current file path.

// app/view/a.twig include app/view/b.twig
{% include 'b.twig' %}

Absolute file is resolve from app/view.

// app/view/home.twig include app/view/partial/menu.twig
{% include '/partial/menu.twig' %}

Layout

You can render a view with layout also:

// app/view/layout.twig

{% include 'header.twig' %}
{% block content %}{% endblock %}
{% include 'footer.twig' %}

// app/view/hello.twig

{% extends 'layout.twig' %}
{% block content %}
  Hello {{ data }}, I'm content. 
{% endblock %}
// app/controller/render.js
exports.twig = function* () {
  const locals = {
    data: 'world',
  };

  yield ctx.render('hello.twig', locals);
};

Configuration

see config/config.default.js for more detail.

Questions & Suggestions

Please open an issue here.

License

MIT

Keywords

egg

FAQs

Package last updated on 23 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts