PeopleCode to Add to Every Fluid Page

I find myself adding these same lines of code in the PreBuild of every fluid component. (As Jim Marion would say, there’s no such thing as a Fluid page, and I would get in trouble for my title.) Normally, I would open another component and copy and paste, but when I move to a new client, that becomes problematic. So, here’s the code for easy copying…

   AddStyleSheet(StyleSheet.<stylesheet name>);
   Local PT_PAGE_UTILS:Utils &oPageUtils = create PT_PAGE_UTILS:Utils();

Maybe this warrants some explanation. First, I always have some CSS styling I want to add. So, I have to add the stylesheet. File > New and create a freeform stylesheet.

Then, I attach it to the component with the AddStyleSheet() method.

   AddStyleSheet(StyleSheet.<stylesheet name>);

The next part makes the page truly fluid. Otherwise, it doesn’t adjust properly to mobile. Of course, you’ll have to import the page.

import PT_PAGE_UTILS:Utils;

Then, just add these lines setting the default view port.

 Local PT_PAGE_UTILS:Utils &oPageUtils = create PT_PAGE_UTILS:Utils();

If you want to go above and beyond, there’s also a method to set the favicon.

&oPageUtils.SetFavIcon(Image.<image name>);

One thought on “PeopleCode to Add to Every Fluid Page

  1. I completely agree. I almost added this code to my own Fluid page template clone of PSL_APPS_CONTENT. But then I realized you only need this code once per component. Therefore, just like you, I use Component PreBuild.

    The one-liner I share in class looks like this:

    (create PT_PAGE_UTILS:Utils()).SetDefaultViewport();

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.