Adding Macros to the Master Template

Matthew Neal asked on August 11, 2017 09:29

Hi Devnet,

I'm working on a project at the moment that requires OG tags on every page. After doing some research, I've come up with the following code:

<meta property="og:site_name" content="SITE NAME" />
<meta property="og:url" content="{% CurrentDocument.AbsoluteURL #%}" />
<meta property="og:description" content="{% CurrentPageInfo.DocumentPageDescription #%}" />
<meta property="og:type" content="website" />
{% foreach (attachment in Documents[NodeALiasPath].AllAttachments) {
"<meta property='og:image' content='" + attachment.AttachmentGUID     + "/attachment.aspx'" + "/>"; } #%} 

Now, I've managed to add it in a 'HTML Head' web part, which works on a per page basis. However, I need this information on every page. I've tried adding it in the master page, but I can't seem to get it to work.

Alternatively I thought I could add it to layout.master, however macros won't work here. I've done a lot of searching and I keep coming up with, well...not much.

Is there somewhere I could put these macros that would make it appear on every page? Alternatively, how could I add it to the master page?

Your help is greatly appreciated!

Correct Answer

Trevor Fayas answered on August 14, 2017 15:18

If you are using ASPX\Portal, the master page is a aspx page (listed as Layout.master), of which you usually cannot put webparts in at all, this may be you issue. You will have to manually adjust your master page to add in the logic to add these items to the header. For macros, you can't just "put" macros in the master page, you will have to resolve any macros using Kentico's MacroResolver.Current.ResolveMacros() and set the values into some control (like a Literal).

This is the major downside to ASPX\Portal, is anything dealing with the master page is pretty locked down and you don't have portal accesses.

From someone who has worked on ASPX\Portal sites, we have found it not worth the hassle and converted them all to Portal. There isn't really anything you can do with ASPX\Portal that you can't do with portal+ some custom controls/webparts.

1 votesVote for this answer Unmark Correct answer

Recent Answers

Trevor Fayas answered on August 11, 2017 14:22

the html head web part in the master should work. what development model are you using? portal, aspx, or aspx+portal?

if not portal then often you end up with a master aspx page that you have to code and you'll have to use the MacroResolver class to render the macros.

are there any errors in the event log?

1 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 11, 2017 17:49

We do this the same way you are showing but if we need something different for different page types, we add multiple head html webparts and set visibility based on page type or alias path. This will allow you to manage all your items on your master template very easy.

1 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on August 11, 2017 18:29

What model of development are you using? Seems like portal engine? If that's the case you can simply add this HEAD HTML webpart in the master template itself thereby it becoming available on every page.

1 votesVote for this answer Mark as a Correct answer

Matthew Neal answered on August 14, 2017 02:22

We are using the ASPX / Portal method. Could I still just put a html head web part in my master template? I did try that and it didn't show anything, so I may be doing something wrong.

This is my first Kentico job so I'm a little in the dark!

0 votesVote for this answer Mark as a Correct answer

Matthew Neal answered on August 14, 2017 07:33

I should also note that our master page is being called in every template with:


And I'm almost positive this is the cause of my issues. I'm getting a feeling I won't be able to use web parts in the Master Template because it won't get called at all.

Alternatively, I was going to put the macros in my 'layout.master' file, however they obviously won't work as a straight copy / paste job. What is the correct process to convert these over to a syntax that will work? I had a look at some of the documentation, but I couldn't find a clear answer.

0 votesVote for this answer Mark as a Correct answer

Development Support Avastonetech answered on August 14, 2017 15:18 (last edited on August 14, 2017 15:18)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.