PHP code in Drupal8 template - twig

How to use normal PHP code in Drupal 8 twig template?
require_once(realpath($_SERVER['DOCUMENT_ROOT'].'/include.php'));

You can't use PHP in a Twig template.
I don't know what you're exactly trying to accomplish but there are many hooks and spots in the render pipeline of Drupal where you can put your PHP logic, so no need to do this "hacky" stuff. Maybe we can give you a hint where to look, if you tell us what your include.php file is supposed to do.

you can attach variable to twig templates using hooks to your templates.
There is no option to use php in twig.

Related

How to set Pagination in Codeigniter without Using Library file

I am new in codeigniter.Is it possible to set core php pagination concept in codeigniter.I dont want to use codeigniter library files to set paghination.i want to create custom pagination concept using core php concept. Can anyone help me to solved this problem.

compare and diff between jade template and mustache template

i am beginner in java script and familiar with client developing in low level.
my question is this that what main diff between jade template engine and mustache template?
both of them is for nodejs server side or use in client side?
what advantage of each in their scope ?
if i want to write small single page app in MEAN stack structure in this case choose of which template syntax is best ? html 5? jade? mustache?
Personally, I like to use Jade especially for the NodeJS apps on the backend side given it integrates well with Node.js and provides a light syntax.
and I use MustacheJS for when I want to use templating within html.
Here is more information on Jade and MustacheJS.
https://strongloop.com/strongblog/compare-javascript-templates-jade-mustache-dust/
http://jster.net/blog/templating-javascript-mustache-jade-transparency#.V0mrXZN96Rs
http://vschart.com/compare/mustache-template-language/vs/jade-template-engin

Which express templating engine should I use for simple code examples?

I'm writing some example code using node and express, that is targeted at beginner to intermediate front end developers (not node.js or express developers). Basically some plug and play code that allows a beginner dev to get right to the HTML, CSS and behavioral JavaScript, and host it on a simple hosting solution like Heroku.
I need a recommendation for a an express compatible templating language that is very light and simple to understand.
I need:
Variables embedded in the template.
Loops and if statements embedded in the template.
I want to avoid:
Unusual syntax (Jade).
Files that are not named .html (like
mustache).
Unusual looking configuration (for example to force mustache to use .html as an extension).
I need something really basic. Should I role my own, or is there a lightweight, well support third party solution I should be aware of?
I would check out EJS. It is pretty decent and fairly easy to use. It is also compatible with Angular. I go back and forth using EJS and Dust.
EJS is very forgiving and easy to get started.

Express 3.x best layout implementation (template engines)

From what I've read, ExpressJS 3, dropped support of layouts, leaving it to the template engines. So if an engine, doesn't have a support for layouts, what's the best Node.js module that will have it? Or if best sounds subjective, not best but at least a working solution?
I'm going to use Hogan.js as a template engine.
Or, maybe there's a better alternative to layouts as a concept? I find it rather helpful but will like to read about other approaches.
There are plenty of template engines.
Here are some good ones I know:
Handlebars - very good extention of {{mustache}}.
Jade - very powerfull template engine from visionmedia (the author of express.js) and my favorite one.
ejs - another template engine from visionmedia.
You'll find more engines here - in this question.
You can take a look of the following templates that is supported in node.js:
https://github.com/joyent/node/wiki/modules#wiki-templating
Also this is benchmark that compares different types of templates according to thier rendering time
https://github.com/Deathspike/template-benchmark
My suggestion:
ejs and jade is very powerful and have a lot of features and both are supported in express
I'm using express-ejs-layouts and works perfectly with underscore/lodash and ejs templates.

How to create simple website using CouchDB only?

Where do I get a tutorial to create a simple website using CouchDB only without any other scripting language. Is it possible to store the HTML, CSS and the Javascript within the document?
Yes, you can store HTML, CSS and Javascript in view documents in CouchDB. Check free online book: http://guide.couchdb.org/
Surprised no one else mentioned this but you can create a "couchapp" which sounds like exactly what you want. CoudchDB will serve up the HTML,CSS, images, scripts directly. http://couchapp.org/page/index

Resources