Pimcore twig editables - Tips & Tricks

What you'll learn with this guide 

This guide will show you how to define and set Pimcore editables before rendering them to make your code cleaner and easier to read, understand and add to. 

Where to use 

Writing clean code is an overall great practice because it makes the further development process easier for developers that come after us. Because of that, it is desirable to do it wherever we can. 
Also, this method can be used in use cases where we need to, like in the following example, use the value of an editable before it is rendered.

Solution

Editables are the essential part of managing content in documents so there will be a lot of them in your code. To make it easier for you and other developers to manage your code, you can shorten it and make it more readable. To understand this, let’s get to the example.

By following Pimcores documentation we learn to use editables like this:

In this example, it is important to instantiate the editable before using it like this:

So after this, we can use our variable which depends on the editable: 

This is the standard way, but in this guide we will show you how to store the editable in a variable so you don’t need to render it until you really need it.

First we store the editable in a variable like this:

By doing this, we can use it before it is rendered:

In the end, we render the editable via "raw" filter where we want to use it:

This way, if you need the value of the checkbox before it is rendered, you can use it unlike in the first method. This makes the programming process easier so it’s very useful.

Does it work? 

Because this guide is pretty straightforward, you can test it by trying it out.

If you'd like some help with Pimcore, feel free to say hello@factory.dev! 

Looking for Exponential Growth? Let’s Get Started.
Explore next

Pimcore Tutorial

Check out our step-by-step tutorials on how to use Pimcore features and solutions.

Discover more