Skip to content
Solid Liquid with Web Templates episode artwork

Dec 23, 2024 26 min

Solid Liquid with Web Templates

from CRM Audio Hosted by crm.audio

In this somewhat warm episode, George and Nicholas explore web templates in Power Pages, breaking down how they work, their history from ADX Studio to modern-day template blocks, the regrets along the way, and practical ways to use them effectively. They discuss features like include and extend, share tips for simplifying your development process, and highlight why templates are a powerful tool for creating reusable components. Whether you're new to web templates or looking to refine your skills, this conversation has something for everyone. As a bonus, they debate what's better as an income stream: Shopify shares or podcasts. Credits Cover image by chatGPT (inspired by terrible prompts) References Web templates | Microsoft Learn Liquid overview | Microsoft Learn Shopify Liquid reference Shopify Stock Quote Get in touch [email protected] Nick Hayduk @Engineered_Code George Doubinski @georgedude

Episode details come from the podcast's RSS feed.

Embed this episode

Ready to play

Solid Liquid with Web Templates

0:00 26:45
of matches

Transcript Auto-generated, may contain errors

You just can't give us Canadians some credit for that, right? Shopify is a Canadian successor, and you just can't give us some credit, hey, George? I have shares in Shopify, so I have strong faith, despite that shares tanked. Yeah, I was going to say, is that why you're still doing this podcast? Because all of your money was in Shopify? Yeah, pretty much.

Good afternoon, Nick. Hello, George. Good to be back with you. How are you? I'm doing well. I'm just enjoying a nice summer evening here in Canada. How about yourself? And I'm enjoying a nice afternoon in Sydney, Australia, which is pretty much just similar to the afternoon we talked last time. Almost like it's the same night.

Almost. It feels like the same. It's a groundhog day. So last time we talked about release notes and what we did touch upon was web templates. And whilst release notes contain some unsubstantiated promises to do magic within the web templates or web templates as components, we did kind of realize that perhaps some of the newer generation of Power Pages builders come to the environment without deep understanding how these things called web templates work. So I thought it would be nice to have a short session about web templates and explain to people what are they and how they work.

You've been involved with them from, I guess, from day one. An ex-member of elite ADX Studio unit, you probably know more about them than anyone else who's currently living in Canada. Yeah, I think if you look way back in history, I think web templates kind of came in at a similar time as the addition of Liquid came in. So they haven't been in there since the very beginning. So I think that's kind of about when they came in, is once the ability to start using Liquid came in, they added the web templates, I think, around the same time. And before that...

there was only one kind of template, ASPX page. But since ADX Studio was kind of dual nature, you could do it yourself. You could write new pages and you can recompile and things like that. And then it had hosted version. And when it was acquired by Microsoft, it went fully hosted. So there was no way to add ASPX pages. So only one type of templates left. And now we had the situation where you had a page template, right? That basically, that's what page is using. Pages link to a page template. So page says, I'm going to use template, three column layout template. And then page template in its turn,

would be one of two kinds. It's either ASPX page, and they still use those for hardcoded, like login page and memberships and membership sign-in pages and things like that. Stuff you have no control over. And 99%, it would be a link to a web template. And web template would be a pure liquid. That's the structure, right? So page, say, what is my template? Goes to template, says what kind of template it is. 99%, it's liquid. So it says, oh, I have a liquid code. Pulls in this code, process it, spits out HTML, done. That's in a nutshell how it works. And that's essentially one use for web templates because

And the web templates themselves are really just a place you can put some code. And then that code can then be referenced in many different ways. So in addition to being referenced as page templates, you can also use web templates for the header and footer of the site. So if you go into your website record or your row in the website table, you'll see that the way you define your header and footer is also via a web template. And I know we'll talk about even more different ways that you can leverage web templates. So at the highest level, web templates are essentially a place where you can put some code. And within PowerPages, there's lots of different places you can reference those web templates so that they can...

do the work that you intend them to do. But I would agree that primarily the fundamental place that you're using these web templates is as your page templates. OK. But out of the way, I mean, how many times you wish that page template didn't exist? It would be just a web template. It's like this unnecessary extra hope, as I said, because you don't have control over the type. So you don't have control over SPX. So leave those alone. Mark those pages as special and be done with it, right? And just have web template. That would be nice because page template as such is just a link. There's nothing there. Yeah, there's nothing we can do with it anymore. Like when you create a new page template, your only option is to create a web template associated with it, right? It's like a mandatory but useless kind of record. Anyway, web templates, templates in general, because it's liquid,

remove the word web, and you can actually go to the specs of the language, whatever language you pick. It's either Liquid or Twig. It's basically, again, we've been through this before, a long time ago when a system in Django world, there was a creation of this language that later split into two, kind of Twig went with PHP, and Liquid is where it went into Ruby world, and then there was implementation, C Sharp implementation, that's what Microsoft uses, and so forth. But Liquid was popularized by Shopify. Effectively, they've taken a lot of credit, deservedly so, they've taken a lot of credit for popularizing it, but the roots of this template language goes further back than that. But anyway. You just can't give us Canadians some credit for that, right? Shopify is Canadian. And you just can't give us some credit. I have shares in Shopify, so I have strong faith, despite that shares tanked. You just can't keep it afloat. Is that why you're still doing this podcast? Because all of your money was in Shopify? Yeah, pretty much.

I wish the podcast paid. But anyway, this aside, so the idea of templates goes back to those days, right? And web templates in Liquid in Power Pages are no different. It's a snippet of code. And then there are two constructs that allows you to kind of work with other templates. One is include.

So template can include the other template. For example, like a page can do, like, give me a header or a footer, like include header or include title or include the breadcrumbs and things like that. So you see a lot of, on the higher level, in a proper design system, you see a lot of include, include, include, include. So I want this, I want that, I want two columns, I want that. So you see common parts coming in together. And nice things about include is that you can pass parameters in. So effectively you can say, I want a multi-column system and you can pass number of columns, for example. Something like that. So you can pass...

I don't know the limits. You can pass multiple parameters into it. But this is a nice way to kind of to create reusable pieces of code. So when you see web templates inside the system, you see like hundreds of those. And you see only dozens of page templates. So how does it work? Because the templates, they're usually nested. The one includes another and so on. They're literally reusable blocks. For example, most recent I've done is when the customer signs in, they wanted to put information about their sales representative into a corner.

photo and phone number and email. So we created basically a short template that spits out a small div and you can embed it any way you feel like. In that particular case, it went to the header, something like that. But there is another construct that people kind of overlook. And we'll talk about it when we talk about components because it's not implemented there. It's extend. Do you want to have a shot at explaining? Because I always butcher it. So what extend does? So extend is an inheritance concept. So you can define in one web template. It's almost kind of like if you go back to the ASP.net world, the whole kind of master page concept where you can define one web template that has

certain areas. And then you define essentially a child web template that you can say, hey, this extends from that parent one. And here are the areas that I want to override. So in effect, I can do something like I can create the page with the header, two columns, for example, and let's say main part and the sidebar and the footer. And that's my layout. And in a master, so to speak, master template, I would define those areas as blocks, but not necessarily fill them in and leave it up to whoever implements or extends my template to say, hey, look, you do what you have to with the sidebar. I really don't care. Here's the area where you can put stuff on the side. And then the child.

template would extend mine and say, oh yeah, I'm going to put some advertisements in there. on the side area and put the content in, so to speak. So gives a nice ability to extend through the blocks. And outside the blocks, the template would lock those regions. So child template cannot touch those. Yeah. And within those blocks, you can provide a default implementation if you want. So you can say, hey, this is what it is. But if the child happens to override it, it can choose to do so-so. It's very similar to the master pages concept in ASP.NET. And combine those two, it actually makes web templates very, very powerful for creating pages. But one of the things that web templates allow you to do, and kind of documentation inside Microsoft, Microsoft is super coy about it.

because I don't see much Microsoft documentation referring to that, even though the EVO we don't speak about, the event management implementation uses those in Power Pages. And that is when you mark template, you define the MIME type and you can say MIME type can be, guess what? JSON. right? Application JSON. And your template doesn't have to return any HTML mockup. It can return just the data. And typically it would be JSON. It can return CSV for like, it returns text. So it produces text. Any template generates text. It's an option for a template to use template as your kind of poor man web service, right? So the key here is that this is where you're going to use the web template via a page template. So you're going to create a page that uses the web template that you're creating. And then there's the most important thing to do is make sure there's a special little checkbox on the page template that you say, do not use the website header and footer. Because normally for most pages you do

if the user is going to see the page, you want that header and footer there. But if you uncheck the use website header and footer, what that means is that whatever web template you choose for that particular page is going to be responsible for the entire output of that page. There's going to be no extra stuff in the header and footer. So then if you define your web template to output some JSON and you go to that page, all you're going to get is that raw JSON and then you can then consume that on other parts of your site. So that's something that can be used and you consume it via typical get call. Remember with those post is not going to work. So liquid by definition is read only. It's one way traffic. So it spits out string. That's what you consume. So you typically it would be a get request to get those to get it out and you can.

parameters, you can do whatever you want. It's just a web template. So one thing specifically about that, where people now that the web API is available, people often ask, does that mean that that format or that that technique is kind of obsolete, but it's actually quite useful in terms of, you know, with the web API, you have to turn it on, you got to enable the columns. And so I always find opening up the web API kind of opens a hole in your security architecture. So you can be a lot more explicit with one of these things. The other thing that allows you to build some business logic into that API, it also allows you to have data from multiple tables automatically just kind of combined into that nice, simple API. So while the read operations that the web API gives you may replace some of the need for that, I still think it's a very useful. Oh, it's super useful. I like

it because with Web API, you're doing your laundry in public. If you want to combine three tables, you will do your laundry. So you go into a laundromat, everyone is going to see holes in your socks and things like that, right? So Liquid allows you, a web template would allow you to hide some of that. You would just give the results. The other area I found surprisingly interesting as potential use, and we did use it on a couple of projects, is ability to generate JavaScript. Let's say somewhere in JavaScript, you need a list of countries, and list of countries comes from list of countries table and dataverse. So instead of using Web API, you literally get it and allow caching do its job. So basically, you produce a pseudos, almost static file.

and it could include JavaScript constructs. It can include a lot of things, right? But the idea is that instead of JavaScript file, you refer to a page that uses web template that produces not JSON, but JavaScript. So the data type will be application JavaScript. Have you done something like that? Yeah, absolutely. Yeah, leveraging the browser cache as a separate file. Of course, you can include that markup directly on the page, but it just kind of bloats the overall size of the page. Yeah, that's hiding it behind. So now we establish the uses of that. What templates typical PowerPage implementation comes with?

There are a couple, I think there are default template. These days, like raw, if you go blank, there is a default template. But when you go to web templates in PowerPages Studio, you see a bunch of templates. Where those come from? So yeah, those are just kind of when you install your PowerPages site and it copies all that data in there. I would guess that some of those are, we're just there because they've been there a long time. And there they are. Of course, the big ones that people are going to get familiar with would be the header and the footer, the web templates in there. But in terms of the page templates, yeah, you're going to get a default. You're going to probably see a blank one. There used to be sometimes like an access to neither some of those other templates in there. But it's been a few years now, that default studio template, that's your primary web template that things.

in the design studio are going to be using? Well, there used to be a folder in ADX Studio deployment. And if you knew the templates in that folder and the way it was done, remember the version eight, the last version that was open sourced, right? If you go there and you see the list of templates and you start trying them out, and though they're not listed anywhere, they surprisingly, they all worked because they still were sitting in that folder. I think by now they brought those templates. They made them public through the official kind of, through the official records inside the web template page. So I'm just opening default implementation that I add template. Yeah, and those are include, you add those using the include. So yes, they're half historic.

been some that you could include and if you happen to know what the names were you could include them you wouldn't see them listed in the web templates list but there was some kind of built into the product that you could review here's the one thing i recommend everyone if you're curious about liquid and you want to learn it there is no better place to learn liquid than go and pull apart those templates for example the simplest template that implements the constructs we talked about extend and include is full page and you go and the first thing it does i'm just looking at it extends layout one column And then you go and say, oh, what does layout one column does? And you start going down this rabbit hole of looking through templates. But there are a couple of really good ones is faceted search. There's a number of templates. They're quite complex. So if you want to know how to generate quite complex layout and functionality, those are good templates to take a look at. And there are also templates that generate sample templates you find in the docs that explain, for example, how to generate list view based on the view from Dataverse, how to generate the layout, the output with the ability to sort columns and things like that. It's quite involved because.

You have to remember things and a few parameters and this and this and that. But those are quite nice templates to take a look at and study. So to me, that's a great way to study. Oh, look at what I found. I found a template called Power Virtual Agents. That no longer works, does it? It embeds the component PVA embedded web chat. That's gone. I believe that's well gone. If I want Pilot the chatbot these days, what do I do? Just go create Copilot? I think in the Maker, in the Design Studio, there's a menu to do that. I think it's in the Setup tab. Yeah, in the Setup tab. At Copilot.

Brilliant. And it's not even in preview. There you go. That's a new way to do it. That was web chat from, what was the company name? I don't even remember. We did the first web chat. It had to do with Java Coffee. Cappuccino. Because they were the reason that the public key, like the Auth Implicit Grand Flow stuff was in there. It was in there for years, even before it was public. Anyway, those guys. That was quite, I think I've done it once or twice, the integration. But anyway, we are digressing. I think I'm going to cut it out. So we don't remember. That's what it is. Oh, ChatGPT remembers. What was the name of the company you provided?

The first implementation of the web chat capabilities for Microsoft Power Apps portals. OK, let's see. LiveX, CafeX, not coffee. Cafe, yes. CafeX. Thank you. But you get coffee at a cafe, right? I mean, that was close. Yeah, that was really close. But this is how you treat copilots, right? You treat them as someone who's willing to help, trying to help, but not quite there. And you say, no, this is wrong. Try again. Try again. Here we go. CafeX. Yes. Mystery solved. Mystery solved. So templates always being kind of the back end of stuff. So you have to go to PowerPages management or portal management, whatever you use.

You use New Model, you go Enhanced Model, you go to Power Pages. You would always go there to deal with those templates. But now you can take a template, add a manifest to it. Manifest being just a... It's JSON. JSON. Oh, well. Can't please everyone. So you add a manifest using JSON that describes your template, and then suddenly this template will appear in Design Studio as a building block, as a component. Am I getting it right so far? Okay. Now, but there are some strings attached. What are the limitations?

So I think the parameters are all strings, as you say, strings attached. Yeah, yeah. So Liquid does have data types. There are very few data types, but Liquid does have data types. It's got numbers. It's similar to JavaScript, I guess. So it's got strings. It's got arrays. It's got objects. But everything is a string in parameters. You can't just pass objects or numbers. So you have to deal with that. I think the extent, obviously, wouldn't be supported, I assume. And include can only go one level deep. So you can't have include, include. I assume the web template that is component cannot include other web templates. That would be the limitation. Now, within what's coming is, and we kind of

couldn't figure out what with the power effects. So there are two areas where power effects can be useful. One is inside the template itself as kind of complementary thing to liquid. Does that work? So you go, what do you go? Curly bracket, effects, column, and then equal, and then expression. Can you do constructs like expression, semicolon, expression, semicolon, expression, like you do in canvas apps? Or it does need to be an expression that evaluates to a string in power effects? That's a good question. I would guess it has to evaluate to a string. So to produce, yeah, same as liquid. Liquid evaluates to a string. Once you parse a liquid.

process, sorry, not parse, process liquid, the output is string. That's it. There is no any other option. So same here, the output of that would be a string. Okay, so you can use PowerFX inside templates, but you can also, they're talking about using command bar when you embed those templates. How would you use it? What would you use it for outside of template? I'm a bit lost here, so help me out. Well, yeah, because when you create those web templates as components, you can then add them in the Design Studio and it's going to give you a UI for any parameters that you're supposed to specify. So I'm assuming you can use then PowerFX to define the parameters so you can use the PowerFX syntax to have some logic about which parameter.

you pass in oh okay so I can do something like for example my template, let's assume my template. I'll give you an example of what I did, like sales representative card that you place somewhere on your page. So my component would be a sales rep card, and parameter would be, let's say, user email. So I would do something like insert my component, and I really don't care about internals. It probably pulls information from a photo from SharePoint, whatever. I'm bending the truth here, but it pulls photo from the column in a user, in a table. It pulls information, whatever, phone numbers, whatever the template does. But it's a component, so I drop it in, and I need to pass user email. That's where I would fire up command bar and say,

say, presumably, there will be objects, something like user. So user.email. And whoops, it goes in there. So I don't have to figure out in Liquid who the user is and this and query the tables. And based on user ID, I need to extract email and things like that. So I can just drop our effects as a user.email and be done with it and pass it in. And template does its best. And it renders the photo and the phone number in the email and whatever. So that's how it would use it. Yeah, I can see it. I can see it being useful. Certainly, that's more maker-friendly than crafting Liquid. Though, I'd say if you're serious about templates and you want

to be a master of them. Learn Liquid using samples, using online samples for Microsoft Docs. Go pull apart the event management implementation. If you have a chance to come across of marketing and event management, pull apart. See how they do it because they talk to web services all the time and they do extensively this using web templates as a web service kind of shim. And then read about include extent, play around with it and treat it as kind of extendable theme. Go read Shopify documentation. Very, very useful. This is actually go-to for Liquid. There are some differences between Liquid in C Sharp Liquid in Power Pages and Shopify Liquid.

but there are a lot of, syntax is the same. So there are a lot of syntax commonalities and expressions, similar expressions. Like if you want to know how to format these or how to find the third element of the array that doesn't begin with letter A or something like this. It's just any words of wisdom from your side, having used templates, what, for 10 years, I assume or so, give or take? Using them for a while, yeah. You know, I'm all about code reuse. So we'll be using them. If you've got that little bit of JavaScript that you find that you're using in a lot of places, too many times I see copy and paste versus throw that in a web template and just include it. That I think is underutilized, quick win on a lot of projects. That's interesting that you mentioned. One of the advantages of spitting out JavaScript is

as web template. Keep in mind, keep it short because it will be embedded into your output. So don't do it for something that belongs in a file. But unlike file, editing files, it's a journey in PowerPages. Templates gives you ability to very, very quickly edit stuff. So if you've got like a piece of JavaScript, it's really easy to edit and just see the results kind of in real time. Whilst if you edit in JavaScript file, it's like you have to go there, pull the file, upload the file, drop the code. The whole thing is just tedious. So for small snippets of JavaScript in there, definitely very, very useful. Okay, on that note, I think we covered all there is to cover about templates. And I can't wait to see what tells will be coming in terms of ability to, for me to bring templates with, for example, as part of the website. Like, can I bundle my website? Can I bring it in? The entire website template that would have.

my own liquid templates and power effects templates and things like that. So we all can stop relying on Shopify shares and retire in peace by selling fuel. I look forward to that day. Okay, me too. On that note, have a good night and until next time. Thanks, George. Always fun.

Frequently asked questions

How long is this episode of CRM Audio?

This episode is 26 minutes long.

When was this CRM Audio episode published?

This episode was published on December 23, 2024.

Is there a transcript available for this episode?

Yes, a full transcript is available for this episode. You can read the complete transcript on the episode page.

Can I download this CRM Audio episode?

Yes. Use the download control on the episode player to save the publisher-provided media file.