The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

cPanel Variables in global_header and global_footer

Discussion in 'User Experience' started by kbisignani, Nov 14, 2015.

  1. kbisignani

    kbisignani Member

    Joined:
    Jan 29, 2012
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I'm working on customizing my interface a little for my users and learned of the ability to add custom content to the cPanel interface by utilizing the global_header.html.tt and global_footer.html.tt files (as documented here: Customize Content in Paper Lantern - Paper Lantern Documentation - cPanel Documentation)

    The problem is I want to pull in end-user data, like User ID, Email Address, etc.

    I can't find documentation on these variables anywhere!!

    But by sifting through files at /usr/local/cpanel/base/frontend/paper_lantern/, I was able to discover variables like
    [% user %] will give me the logged in user

    But this doesn't work in the global_header.html.tt file. If I put my code into /usr/local/cpanel/base/frontend/paper_lantern/_assets/master.html.tt it works great! But I know as soon as my server gets an update, this code will get wiped out.

    So my question is two-fold:
    1) How do I get cPanel variables to work in the global_header and global_footer files?
    2) Anyone know where I can get other data elements, like user email address?


    Thank you to anyone who can shed some light on this!
     
  2. kbisignani

    kbisignani Member

    Joined:
    Jan 29, 2012
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I wanted to post a reply because I hate stumbling on old threads with no answers!!

    First, thank you Michael, what you sent didn't exactly answer my question, but got me pointed in the right direction of the Template Toolkit and how existing Paper Lantern pages were built. By understanding that - and reviewing existing pages built in /usr/local/cpanel/base/frontend/paper_lantern - I got something together that worked.


    The key here is that all the fancy stuff in the [% %] tags matches some sort of an API call or something along those lines. I used existing Paper Lantern pages to then derive what I needed in order to make this work. So while their might be a better way, this is what was inside Paper Lantern so I went with it.

    Technical Note: I did this work in the global_footer.html.tt file so it doesn't get erased when cPanel/WHM updates.

    To get the User Name, I first have in my file the following code:
    [%-
    USE UI_Includes;
    SET user = ExpVar.expand('$user');
    -%]
    And then I can use [% user %] anywhere in the custom global footer file.

    Next up, and a little more complicated then I'd like, grabbing the account holders email address. Like before, you need to start with some code to tell the file you want to pull this information. For this I used....
    [%
    Api2.pre_exec("CustInfo", "contactemails");
    SET contactemails=Api2.exec("CustInfo" , "contactemails" , {});
    Api2.post_exec("CustInfo", "contactemails");
    %]

    And then, this is where it's a little strange, the email address is stored in an array of sorts, and to pull out the primary address (all I wanted), I had to use the following code:
    [% IF contactemails.size() %]
    [% FOREACH contactemail IN contactemails %]
    [% IF contactemail.name == "email" %]
    [% contactemail.value %]
    [% END %]
    [% END %]
    [% END %]


    That's a lot for just a simple email address - but it guarantees that 1) Only do this if an address exists, 2) Loop through the array and 3) Only pull the primary email address. The options here are email and second_email (as documented on this page: cPanel API 2 Functions - CustInfo::contactemails - Software Development Kit - cPanel Documentation )


    Again like I said, there might be a neat and tidy way of doing this that I didn't do - that I don't know how to do. But, I can confirm this works.

    P.S. If you are wondering why I'm doing this, I've integrated a support widget that is displayed within the cPanel pages to my customers. By pulling these values I'm able to pre-load the widget with information I want submitted with the ticket without asking the end user to enter it themselves.

    Thank you again Michael for pointing me in the direction I needed.
     
Loading...

Share This Page