A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pug-php/pug-symfony/tree/2.8.0 below:

GitHub - pug-php/pug-symfony at 2.8.0

Pug template engine for Symfony

In the root directory of your Symfony project, open a terminal and enter.

composer require pug-php/pug-symfony

When your are asked to install automatically needed settings, enter yes.

Note: Since the version 2.5.0, running the command with the --no-interaction option will install all settings automatically if possible.

It for any reason, you do not can or want to use it, here is how to do a manual installation:

If you installed Symfony in a custom way, you might be warned about missing "templating.engine.twig" service. We highly recommend you to install it (composer require twig/twig) to get Twig functions such as css_url, form_start and so on available from Pug templates.

If you're sure you don't need Twig utils, you can simply remove "templating.engine.twig" from your "templating" services settings.

You can set pug options by accessing the container (from controller or from the kernel) in Symfony.

$services = $kernel->getContainer();
$pug = $services->get('templating.engine.pug');
$pug->setOptions(array(
  'pretty' => true,
  'pugjs' => true,
  // ...
));
// You can get the Pug engine to call any method available in pug-php
$pug->getEngine()->share('globalVar', 'foo');
$pug->getEngine()->addKeyword('customKeyword', $bar);

See the options in the pug-php README: https://github.com/pug-php/pug And methods directly available on the service: https://github.com/pug-php/pug-symfony/blob/master/src/Jade/JadeSymfonyEngine.php

Initial options can also be passed in parameters in your config/services.yaml in Symfony 4, config.yml in older versions:

parameters:
    pug:
        expressionLanguage: php

Create jade views by creating files with .pug extension in app/Resources/views such as contact.pug with some Jade like this:

Then call it in your controller:

/**
 * @Route("/contact")
 */
public function contactAction()
{
    return $this->render('contact/contact.pug', [
        'name' => 'Bob',
    ]);
}

In production, you better have to pre-render all your templates to improve performances. To do that, you have Pug\PugSymfonyBundle\PugSymfonyBundle in your registered bundles. It should be already done if you followed the automated install with success. Else check installation instructions (add bundle in Symfony 4+, add bundle in Symfony 2 and 3)

This will make the assets:publish command available, now each time you deploy your app, enter the command below:

php bin/console assets:publish --env=prod

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4