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.

My highlights for “The Elements of User Experience”

Lately for a project I’m involved on (and about which I’ll talk in a later post) I’m studying and reading a lot about User Experience.

I’m not new to the concepts of good UX and I’ve read a lot of articles in the past ten years. What I’ve missed is a comprehensive overview of the subject. A couple of friends suggested me to give this book a try, and I was glad I did.

You can sense from the screenshots and the examples that this is an “old” book, but if it weren’t for these aging assets, it could have been written yesterday.

I’m often surprised when something is so well written and explained and yet during our days we keep reinventing it and trying to get the buy-in for processes that should be straightforward in web development. It’s like civil engineers had to always reinvent the way you build a skyscraper!

But enough of my ranting, here are my highlights from the book.

Continue reading “My highlights for “The Elements of User Experience””

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”

How to excel as a developer, designer, marketer (or anything else)

Little actions, repeated in time, transform us.

I have always been very curious and since I can remember I was interested to know how to learn better.

Why should we improve ourselves

Obviously, the first question that we have to ask ourselves when we begin a new path should be “Why should I do it?”.

We have already so little time that it would be stupid to waste it with tasks that are not worth to do (and Netflix is coming out with a lot of interesting new series!).

Why should we improve ourselves, then?

Continue reading “How to excel as a developer, designer, marketer (or anything else)”

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.

Back from the holidays: hiking around Monte Bianco

When I was younger, I usually went hiking with my dad.

He had one of those hiking guides that lists all the walks in a certain region; I still remember the name: “Il Cammina Campania. Guida WWF”.

I have wonderful memories of those walks: the early wake-up, me sleeping in the car, the 4+ hours of walking, collecting dead branches to create our very walking sticks…

Since then, though, I didn’t hike so much. Just some random walks in nearby parks, or something like that.

So when I and Valeria were planning our holidays I asked her if she’d like spending a week walking around the mountains. And she said yes!

It was great! 

I feel so refreshed and full of energy, that I’m asking myself how I’ve survived without this for all of these years.




My 2017 reading challenge

Some books with a candle

Last year I decided that I wanted to read more. So I set myself a goal to read 53 books in one year. I failed (That’s a recurring theme).

During the challenge, that started the 31st of October 2016, I managed to read ~25 books. Here they are:

  1. Intercom on Product Management Great book
  2. Docker for Developers meh
  3. Liminal Thinking: Create the Change You Want by Changing the Way You Think I need to read this again
  4. 97 Things Every Programmer Should Know: Collective Wisdom from the Experts Lot of insights
  5. Modernizing Legacy Applications in PHP Really well written
  6. Digital Marketing For Dummies I don’t usually read marketing books, but this is good
  7. La luna e i falò A Masterpiece
  8. Alice in Wonderland A classic
  9. Contagious: Why Things Catch On You need to read this!
  10. Warren Buffett Style: Regola n.1 non perdere mai denaro What was I thinking? Awful
  11. Start with Why: How Great Leaders Inspire Everyone to Take Action Maybe I need to re-read this. I didn’t like it
  12. The Time Machine Wow!
  13. The War of the Worlds Slow, but good
  14. Demystifying Public Speaking A good piece on the topic
  15. The Digital Photography Book 1 Sometime you need to move on
  16. Blockchain Basics: A Non-Technical Introduction in 25 Steps To understand what was it all about
  17. The Principles of Successful Freelancing I had the idea to start freelancing
  18. The Adobe Photoshop Lightroom CC Book for Digital Photographers I like retouching photos
  19. The Minimalist Photographer And also travel light
  20. The Best of The Digital Photography Book Series Same as above
  21. Travel and Street Photography: From Snapshots to Great Shots And travel
  22. Beyond Legacy Code A nice read
  23. Growing Object-Oriented Software, Guided by Tests If you’re into testing, you should read this book
  24. A Common-Sense Guide to Data Structures and Algorithms: Level Up Your Core Programming Skills Very basic, but if you need an introduction, it’s perfect
  25. The Little Black Book of Decision Making: Making Complex Decisions with Confidence in a Fast-Moving World I really loved this book: it’s packed with knowledge

So I’ve read less than half my goal but, jokes aside, I don’t consider it a failure. I’ve read more in 2017 than in the previous two years!

Tips to read more

Social media has taken a toll on everyone. I discovered myself more than I like to admit browsing endlessly streams of jokes, links, articles (I’ll just save it and read it later…yeah sure), tweets, photos and so on. But I also discovered that I could just stop. I trained myself to stop being a social media zombie and read instead.

Everyone imagines that to read you have to be sitting on your favorite couch, beside a fireplace, drinking hot chocolate while outside the snow falls covering the ground. How romantic. Yes, there are situations like this and they happen in the movies. We live in the harsh reality, we should be guerrilla readers.

No, that’s not how we read everyday

The trick is: read everywhere, even if a single page or paragraph. In a queue? Read. Waiting for the doctor? Read. Stuck in traffic? Listen to an audiobook. To the dentist? Run! 😀

My friends know that I swear by Safari Books Online: the thing that I like the most is that it enables me to access and download all the books on my smartphone, so that I don’t need to bring with me yet another device (I’m looking at you, Kindle. It was nice, but you know that it never worked between us)

2018 edition

So have I stopped? Of course not. But only stupids don’t learn from their mistakes.

So for this year I’ve decided to start from January to December (so that I can track my results in Goodreads better). And since I don’t think that I’ll be able to read a book a week, I’ve decreased the target to 40 books. That’s a bit more than last year.

So, are you up to a challenge? Connect with me on Goodreads