 reusable functionality for front-end development. Yes and first of all I worked for a company called Roho Media and we are a small agency specialized in Drupal development. I worked for this company since three years now and beside on working Drupal projects I have two passions. First is Symphony. I'm first a Symphony developer and I also wrote a few bundles for Symphony and my second passion is running. This is a very current picture of mine running 55 kilometers in the woods and in the trails. I love it. Yes and you can find me on Strava and this my Symphony bundles is a very much a bunch of bundles. Yes and today I want to talk about preprocessed functions also in the second place and preprocessed functions are the first thing I noticed as a Drupal developer coming to as a Symphony developer coming to Drupal and I was wondering when I opened a template where are these variables coming from and my colleagues said to me oh this you have to preprocess it yes and I wanted to ask you a question who of you did ever use a preprocessed function also created one okay who created a tweak extension oh much less yeah okay who of you create a tweak extension for every project oh okay because when I start a project in Drupal I every time the first thing I do I create an app module and I create a preprocessed function that's the first thing I do I never ever come on the idea to to use preprocessed functions also never ever because I am in the first place a symphony death and coming from symphony it's absurd I never would do this yes and I was talking about this and developer said to me oh tweak is only to to print out variables who thinks this is right okay yes you know I was wondering because I was saying okay when this is true why we are using tweak I mean plain PHP would do the job no problem yes and yes I want to talk about these advantages of preprocessed functions when you write a preprocessed function you have limited readability because someone want to edit the site and sees this nice comments in the death mode to see okay this is node HTML node projects HTML and find it and read it and these content or node and inside of this node array render ray on then next to this more render rays and nobody knows really where is this coming from yes and it's not really reusable because what I have seen is you write this preprocess functions over and over again and this preprocess functions this dot module file is huge it's like I saw a dot module files over 2000 lines of lines and is very very huge and and it's less flexible yes because when you write preprocess functions maybe you want to write a module like the node module and you say okay I have a template and every template has to have this node variable preprocesses inside my template and maybe some logic inside the problem is the developer comes and wants to edit the template and sees only node they can do nothing with it nothing they have to find a way to preprocess it again and to change what's inside of this array array in array in array and this can be very messy yes but what's the solution the solution is the symphony day for me and like I said I work three years now as a symphony as a two-point developer and I never ever used a preprocess function only for one thing and this I will show you yes to create a tweak extension is very easy so you have to you have to write a class and you see here Drupal app I don't I don't name my module I name a module every time app like a symphony death and yes and that's it you need this global interface only when you want to use global if not then you can pull the way it have to extend abstract extension and then you can use functions filters and other stuff then you have to register it as a service yes the important thing is the tag have to be tweak extension and that's it you can start flush the cache and then you can start you know and tweak extension extensions are a way to extend tweak this template engine yes and you can do very cool stuff with it with it Drupal itself provides us with extensions as with a tweak extension class and these are functions everyone knows these functions yeah like like attach library it's very easy to use this and yes create attribute I use it every time everywhere every day the next you have the filters you can have this filters like trends T without render yes and there are even popular modules like tweak tweak and bamboo tweak you can render forms render blocks regions views entities and apply image styles create render arrays from entities field lists field items and there is even a way to write plain PHP with this PHP filter very easy I never use it I would never use it but it's cool that it exists yes and I have written an example for you how I use tweak extensions in my project and this is a small partial in a project and you have here this get term children and it's very easy and very readable you see what's happening here it's it's not you have a term children here as a variable and you don't know where it comes from you see okay you have the product the product and you can print it out and then you see okay here it gets it's getting fetched then you have to get translation also and the nice thing in the ID is you can every time use command click and the ID jumps to the code it's abstracted like a preprocessed function but you can every time jump to the code and also in mine in my PHP storm it's very easy to jump and this is not the case when you use preprocessed functions as we have to search where is it and this is very easy you click on it and you are there yes here's the code very easy you can see get term children you fetch the entity manager get the storage load the children and you can use it there and the same is forget translation you fetch the translation next example is how I use sometimes the globals in this case I have a ray and this is only styling inside and in this styling class is there are some terran C's as classes I use around the the the project and these are tests you can even test like instance of is often used is object is string yes I use it like this here you can see the instance of test and this is just an example I would never do this in a real world in a real life project who knows who can you do this better how you can do this better any idea also this line this PHP and instance of it's very long to show you this test when you want to do this more clean what you can do what as I would do I would create a big extension filter this and it's very readable PDF is major object you can you create your PHP code and then get the download download well and this is also a filter I can easily write and reuse in every project in every template wherever I want to yes it's very short very readable when I read this I know it exactly what's happening what's happening here yes and for every project we create we are creating our own tweak extensions filters tests globals and functions and then we came across this craft CMS does somebody know something about craft CMS it's a small CMS and I wrote two years ago a block kind of side with it and they have this entity queries you can fetch data from your tweak templates and reuse and use it and I was wondering maybe we can create this for a triple and this is the result yes you can as you can see you can query entities by type you can add conditions order by limit and then of course you can fetch it yes it it's like this you can set your variables query for entries and this entries maybe I should have called it nodes because in the end these are nodes but in craft CMS it's called entries and I called it entries now it's called entries yes but it's a node from type object and you fetch all that's very easy and you can do this even for taxonomy terms yes the next example you query a node of type project where the title is target and you fetch it all here you query a node of type project and this is a condition group with titles target and description my description and fetched all this is a complex example and I have to say I would never do this in a real project it's only for example here because it's too much what you what do you think what you can do to make this even more cleaner and not so big a function I would create a big function like fetch similar codes and then do this stuff inside the function and if I'm interested later what's happening there I press my command thing and I see the PHP code this is too much I I don't want to recommend you doing this inside your tweak template but it's is showing what you can do with this this is more you here you are querying nodes of type article and you see what tags are inside and fetched nodes of the same tag also containing the same tag yes takes like taxonomy text yes that's the next point yes yeah and the same you do with the with the category you see if there is a category one category you map over it because the in and this this entity query needs an array of IDs and then you add the condition and you get you can change it you can change it as you can see you can change this all together and in the end you order it limit it print it out and iterate over it it's very easy what's the downside of it like you already mentioned the downside of using this module is caching of course you have to set your own cached text like I did here and this is the one of the very less occasions when I use preposets functions to set this case this cache text or cache contexts yes and by now it's only for nodes and taxonomy terms it's not for for any entity but this is something we we are thinking about because it would make sense of course yes thank you very much for your attention and I hope you will use often more often tweak extensions and less often preposets functions any questions yes tweak query google it it's yes it's it's tested it's documented you can use it hi I remember doing all this sort of stuff in who's talking okay okay in in twig templates and being told off by a symphony developer that you shouldn't put sort of logic and complex stuff in twig templates yes whereas where is where is the world at we seem to be going like no it's like this he's right yes yeah yes because I told you when you saw this big chunk never do this it's much here it has to be small and precise and you have to make it like it's good readable so call a function but all the main logic yes and maybe make a function with parameters to make it more granular that's nice yes cool yes not make big twig templates with if it that's not what I tell you