Skip to content

Instantly share code, notes, and snippets.

<?php
# src/Acme/HelloBundle/Twig/AcmeExtension.php
namespace Acme\HelloBundle\Twig;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Locale\Locale;
class AcmeExtension extends \Twig_Extension
{
.highlight .hll { background-color: #49483e }
.highlight { background: #272822; color: #f8f8f2 }
.highlight pre { background: transparent; color: #f8f8f2 }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
require 'posix-spawn'
require 'rbconfig'
##
# Wrapper for the Pygments command line tool, pygmentize.
#
# Pygments: http://pygments.org/
#
# Assumes pygmentize is in the path. If not, set its location
# with Albino.bin = '/path/to/pygmentize'
auto: true
destination: ./web
exclude: sass, config.rb
permalink: /:categories/:title.html
markdown: redcarpet2
redcarpet:
extensions: ["no_intra_emphasis", "fenced_code_blocks", "autolink", "strikethrough", "superscript", "with_toc_data"]

Configure a site for automatic deployment via Git

Go on the production serveur, then create two folders:

  • one for the git repo that will receive updates and deploy it automatically, for example: /home/user/git/livesite.git/
  • one that will be the live site folder and contain all the website files, say /home/user/www/livesite/

Go to the git repo folder

$ cd /home/user/git/livesite.git/

Fixing issues when installing Gitlab

$ sudo apt-get install -y postgresql-9.2 postgresql-server-dev-9.2

fails

Solution:

$ sudo add-apt-repository ppa:pitti/postgresql

$ sudo apt-get install -y postgresql-9.2 postgresql-server-dev-9.2

How to login a user programatically in Symfony2

First, insert use statement at the top of the file:

<?php

use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
<!-- Customize data-prototype attribute for embedded form collection in Symfony2 -->
<!-- form.html.twig -->
<div id="playerFields" data-prototype="{% filter escape %}{% include 'AcmeTeamBundle:Team:prototype.html.twig' with {'form': form.players.get('prototype')} %}{% endfilter %}"></div>
<!-- prototype.html.twig -->
<div>
<!-- Customize form element rendering as you wish like any other form element -->
{{ form_label(form.name) }}
$('SELECTOR').click(function(e) {
e.preventDefault();
if(confirm("MESSAGE TO DISPLAY TO USER") === true) {
window.location.href = $(this).attr('href');
} else {
// User Cancelled
}
});
<?php
$form = $this->get('form.factory')->createNamedBuilder('profil_candidat', 'form', null, array(
'constraints' => $collectionConstraint,
))
->add('name', 'text')
->add('email', 'email')
->getForm();