webdev && sysadmin quips, tips, articles + more

Twig Cache File Permissions

| Comments

If you are having problems with the permissions of the cache files that Twig compiles this may point you in the right direction.

To bring you up to speed, Twig will compile Twig templates into native php once parsed, this ensures that they are rendered as fast as possible.

My specific use case is that some templates are compiled on the command line as a different user than apache which compiles them from web requests. When generating templates from various users I ran into permissions where the cli user couldn’t create cache files in folders that were previously created by Apache. The cli user and Apache both are in the same group so I just needed to make sure that all folders and files (for clearing the cache) are owned by the common group, which is easier said than done.

Quick Tip: Rawurlencode in Twig

| Comments

I’ve been working on modifying listserv digest emails at work and porting them to Twig templates. The fun part was trying to create mailto: links that mimicked hitting reply (auto populating the subject with RE: [post title]).

The problem with just jamming the title in to the ?subject= param is all sorts of fun like spacing and special characters. Turns out that you can use a Twig filter to urlencode a variable: Twig - urlencode filter

Under the hood Twig’s urlencode filter uses php’s urlencode. If you use the urlencode filter you may notice one slight issue, spaces are converted to + instead of %20. According php.net the solution here is to use rawurlencode instead of urlenccode. Well how do you go about calling the rawurlencode filter if it doesn’t exist?

RTFS! I couldn’t seem to find out why rawurlencode wasn’t an available filter and really didn’t want to roll my own, it turns out if you read the source you fill find an nice undocumented feature. Instead of creating a new filter for rawurlencode all you need to do is pass true to the urlencode filter!


Next step is to make a pull request and update the docs to be more verbose!


Quicktip: Read From Stdin in PHP

| Comments

Quicktip: Add Conditionals in a WHERE Clause

| Comments