Geddy EJS templates, import partial templates

For Geddy version 0.11.8.

Here is a typical directory listing for some template files.

> app > views > something >
--------------------------> index.html.ejs
--------------------------> _fruit.html.ejs
--------------------------> _apple.html.ejs

To correctly reference the sub templates in the index file, supply the ‘something’ folder in the path. Optionally: theData is an object that supplies data to the partial.

<%= partial('something/_fruit', {myData: theData}); %>

Geddy SyntaxError: Unexpected token catch at Object.Function (unknown source) at Template.compile

Working with the Geddy nodejs framework, I got the following error. I knew it was to do with a view file (using EJS templates).

Error: 500 Internal Server Error
SyntaxError: Unexpected token catch at Object.Function (unknown source) at Template.compile (/usr/local/lib/node_modules/geddy/lib/template/engines/ejs.js:88:10) at ejs.compile (/usr/local/lib/node_modules/geddy/lib/template/engines/ejs.js:25:18) at ejs.compile (/usr/local/lib/node_modules/geddy/lib/template/adapters/ejs.js:24:22) at Adapter.compile (/usr/local/lib/node_modules/geddy/lib/template/adapters/index.js:105:32) at Adapter.render (/usr/local/lib/node_modules/geddy/lib/template/adapters/index.js:125:40) at Partial.renderSelf (/usr/local/lib/node_modules/geddy/lib/template/partial.js:126:28) at Partial.render.handleData (/usr/local/lib/node_modules/geddy/lib/template/partial.js:99:16) at Partial.render (/usr/local/lib/node_modules/geddy/lib/template/partial.js:117:9) at fs.readFile (fs.js:176:14)

Turned out I had a type on a closing for loop:

 
<& } %>  // error
 
..
 
<% } %>  // corrected

Add bootstrap3 to a symfony project with composer

This post covers adding bootstrap without using bundles.

Add the requirement to your project composer.json, and run composer update

"require": {
    ...
    "twbs/bootstrap": "dev-master"
},...

Bootstrap will now be present at vendors/twbs/bootstrap

My preferred method of working with bootstrap is to create your own style.less, and import the bootstrap.less directly. Any variables can easily be overridden, and this results in a single compiled CSS file.

Make sure you have the correct directories in your bundle, we want a less folder and a css in Resources/public.

/src/Namespace/Bundle/Resources/public/css
/src/Namespace/Bundle/Resources/public/less

Create a symbolic link to the bootstrap less files:

Windows: (required administrator access)

cd src\Namespace\Bundle\Resources\public\less
mklink /D bootstrap ..\..\..\..\..\..\vendor\twbs\bootstrap\less

Create your style.less file Resources/public/less, and you can import the bootstrap less file and start styling up your application.

I use an external tool to compile my LESS into CSS (into ../css/styles.css) but there are plenty of tutorials to compile LESS via Assetic if thats what you prefer.

Google Tag Manager – Analytics Page View Setup

How to set up Analytics tracking with Google Tag Manager.

Add a new account.

account screen

Create a container for your website. I also create a unique container for each testing environment.

Select web pages or mobile apps as required. The following instructions follow the web pages option.

For web pages tracking, you can associate a domain to the container and configure the locality.

screen2

The overview screen shows current tags, rules and macros associated with this container.

screen3

Add a new tag to the container. You want to call it Analytics or something else obvious. Select Google Analytics from the Tag Type field. The other fields allow you to configure how the Analytics tag. Most important are Web Property ID, to link it to the correct account.

screen4

You now need to add a rule to the tag, to tell it which pages it should fire on. Here we will tell it to fire the Analytics tag on all pages.

screen5

Save your tag. The Create Version will create a snapshot of your container.

screen6

Finally, Publish the container.

screen7

All you need to do now is remove any existing Analytics code off your site, and replace it with the Tag Manager code snippet. This can be found under Users & Settings > Settings menu.

Git Deployment and Branching Stratergies

The branching strategy outlined by Vincent at nvie.com is what I use myself.

This posts adds a few Git commands I find useful in my day to day work.

Pushing a release branch to a remote server

$ git checkout -b release-1.2 develop
$ ./bump-version.sh 1.2
$ git commit -a -m "Bumped version number to 1.2"

If I want to push this release branch to another server, I can do so via origin in the standard way:

$ git push origin release-1.2

And then on the remote server:

$ git fetch origin
$ git checkout -b release-1.2 origin/release-1.2

console undefined error when using Google Content Experiments API

I was setting up some google content experiments using the new content experiment API. When testing in legacy IE, I came across a ‘console is undefined’ error message.

To fix this error – and allow the experiments to run on IE, add the following javascript above your experiment script import.

<script type="text/javascript">
    if (!window.console) console = { log: function () {} };
</script>

Adding a table prefix to your Doctrine Entities in a Bundle

How to add table prefix to your database tables for all Doctrine entities in a Symfony2 bundle. Most of the information found on this article worked fine: Symfony2 Doctrine Table Prefix

Modifications for using XML format for services.xml.

    <parameters>
        <parameter key="acmebundle.db.table_prefix">prefix_</parameter>
    </parameters>
 
    <services>
        <service id="acmebundle.tblprefix_subscriber" class="AcmeBundle\Subscriber\TablePrefixSubscriber">
            <argument>%acmebundle.db.table_prefix%</argument>
            <tag name="doctrine.event_subscriber" />
        </service>
    </services>