Blog

Developers

Aug 9, 2010

Global Tags - Guest Post By Jeremy Hamel

Global Tags

While working on the new demo site for Aptuitiv, I came across an issue. I had designed the site to utilize the Accounts feature in the Site Template. As you may know, you can pull in account information of the user currently logged in by using Global Tags. I hadn’t featured this in any of my designs yet, so I thought I would try it out with the demo site. We are using a lot of the modules that utilize the Account settings and having an easy one-click solution in a prominent location seemed ideal to me. Sounds great, right? Well, unfortunately, Global Tags are not currently supported in the Site Templates but I have been told they will soon. Global tags are supported in Content Template, Navigation Template, Widget Template and Page Content Block Layout Templates. So what to do in the meantime? I was at a crossroads in the development process: change the design or find a solution. Being the stubborn designer that I am, I went on a mission to solve the riddle. What I came up with was a workaround worth sharing.

I needed something that could be pulled into a Site Template. Enter the APIs. For my example, I used the Post Filter API for the Blog module. Content Templates for APIs are usually used to show specific content for the module it represents. It can also be used, as I found out, to display Global Tags. Below is the sample code for the Content Template:

{if #global.user.isLoggedIn = false}

<a href="{#global.loginUrl}">login</a> | <a href="/account/register">register</a>

{else}

Hi, <a href="/account">{#global.user.firstName} {#global.user.lastName}</a> | <a href="{#global.logoutUrl}">logout</a>

{/if}

Using some simple logic to check to see if the user is logged in, we display either the login and register links for .isLoggedIn = false or display an account edit (in the format of a greeting and display name) and logout links for .isLoggedIn = true.

Stick the code in a Content Template for an API, format the API tag to use the correct template, and plug the tag (such as {ap_api:blog:recentPosts templateId="5"}) into any part of your website to have Global Tags anywhere you want.

Enjoy your new found wisdom and happy coding!

Jeremy

About the Author

Jeremy Hamel is President of Sliced Design, a design company based in the Greater Boston area, focusing in web and online technologies. Before starting his own company, Jeremy was onboard at Aptuitiv helping to design and develop Aptuitiv Studio, so he probably knows a thing or two about the software.

Sign up for our newsletter to receive invaluable information about BranchCMS, web design & development.