Eleventy: React/Vue-like components in nunjucks with macros

I’m experimenting a lot with Eleventy lately, and with nunjucks, since it’s one of the supported template engines.

Today I wanted to create a reusable container macro to avoid repeating the same wrapper over and over. I first tried with a macro like this:

{% macro section(items = []) %}
    <section class="my-section">
            {%- for item in items -%}
                {{ item | safe }}
            {%- endfor -%}
{% endmacro %}

It worked. But the downside was that I had to write the HTML in strings. Ugh!

      '<p>My first paragraph</p>',
      '<p>My second paragraph</p>'

So I started reading the official documentation and stumbled upon the call tag. It’s not super-intuitive, but it was exactly what I was looking for.

It allows you to wrap a macro call around some content, so that it’s passed to the macro body. As always an example is worth a thousand words. We change the section definition as such:

{% macro section() %}
    <section class="my-section">
        {{ caller() }} {# This is where the content will be placed #}
{% endmacro %}

And we can call it like this:

{% call c.section() -%}
  <p>My first paragraph</p>
  <p>My second paragraph</p>
{%- endcall %}

Much cleaner, and we can also customize the section by passing in some arguments. But this will be the topic of another post.

A PHP time-lapse: tools and resources for Modern PHP

PHP has come a long way since its humble beginnings as a simple scripting language and Modern PHP has several peculiar traits (see what I did there?)

But with a simple Google search along with great material about how to write Modern PHP you will find a lot of outdated blog posts or resources that should be ignored.

In this post, I’ve tried to collect a few outstanding resources that have helped me become a better PHP developer.

But first, the time-lapse.

Continue reading “A PHP time-lapse: tools and resources for Modern PHP”

Your improvement is your responsibility

Karate at dawn

I really liked the introduction from the book Exercises for Programmers, by Brian P. Hogan:

Practice makes permanent.

A concert pianist practices many hours a day, learning music, practicing drills, and honing her skills. She practices the same piece of music over and over, learning every little detail to get it just right. Because when she performs, she wants to deliver a performance she is proud of for the people who spent their time and money to hear it.

A pro football player spends hours in the gym lifting, running, jumping, and doing drills over and over until he masters them. And then he practices the sport. He’ll study plays and watch old game videos. And, of course, he’ll play scrimmage and exhibition games to make sure he’s ready to perform during the real contest.

A practitioner of karate spends a lifetime doing kata, a series of movements that imitate a fight or battle sequence, learning how to breathe and flex the right muscles at the right time. She may do the same series of movements thousands of times, getting better and better with each repetition.

The best software developers I’ve ever met approach their craft the same way. They don’t go to work every day and practice on the employer’s dime. They invest personal time in learning new languages and perfecting techniques in others. Of course, they learn new things on the job, but because they’re getting paid, there’s an expectation that they are there to perform, not practice.

Brian P. Hogan

Pay me and teach me

Too often software developers complains that their employer should be held responsible for their formation. 

That’s so far from the truth! Your employer is paying you to perform, not to learn.

Of course, a learning-friendly environment is something desirable, but that not a strict requirement to continue learning and improve on your craft.

AI Playbook

We’ve written the survey specifically as a starting place for business and technical people just beginning their own journeys with artificial intelligence and are teasing apart what’s real from what’s hype.

We assume you are involved in creating, managing, or green lighting software and want to understand how AI can give your software super powers

Read on: A 16 Z AI Playbook

Is jQuery still a thing?

There’s a big stigma around using jQuery lately . It seems like everyone is insistent on avoiding it in modern JavaScript development. Lately developers are all talking about things like TypeScript, ECMA2015+, and the current flavor of the month framework.

I think this is silly. jQuery is still very much relevant in 2017 — it just isn’t getting talked about.

Read on: I Still Love jQuery — And You Should, Too.

Potential roadmap for multisite

Three plus years later, we’re still finding oddities in old MU code, so it makes sense to bide our time and only undergo renames when they let us shed dead weight. The side effect of keeping the barrier to entry high for multisite is not necessarily a bad one — even three years after merge, the product as a whole is still very weak (which is being kind).

Source: Potential roadmap for multisite: Subdirectories, subdomains, open registration, and domain mapping – Make WordPress Core

On interruptions and growth

Like seeds in the soil, software developers must grow

Today was a tough day: one of those days when you’re trying to achieve your todo list items, but it just seems that the world is against you. Then I had an epiphany.

As many of you know, I’m a software developer. I always thought that my job was to produce lines of code, to design software systems, to review pull requests, and so on.

So I consider every day that I’m unable to write at least a line of code a wasted day.

“So what is preventing you from doing your job?” I hear you asking.


“Did you wrote this part of the system last year? Can you help me? I have to extend it…”
“Can you help me with this git command?”
“I just wanted your opinion…how would you solve this problem, given these constraints?”

So, today, when I was sitting at my desk for the first time at 4 pm, 8 hours later I entered the office, I was furious to see Slack notifying me yet another “Can you help me with..” message.

But then, it happened.

I realized that, despite the fact that I haven’t produced a single line of code, I enabled more than ten people to continue their work.
I helped all those stuck people to overcome a simple issue that was preventing them from keeping on working.

So, instead of being bothered, I decided to be proud. Instead of being shallow, I decided to give every person the time he needs to understand deeply what he’s asking me.

And I like to think that, as I’m growing as a person, my professional side is also changing, growing and adapting. Taking me to my next challenge.

So, the next time that someone asks you for help, think that they’re helping you grow.