三三世界-百宝箱

文章 分类 标签
130 9 247

公告

暂无站点公告

How can i add lines to WHMCS Admin Addon Module Template {headoutput}?

三三 2021-11-27 1508 0条评论 Linux使用 WHMCSheadoutput

首页 / 正文

First of all, I am new here and my English is not good enough so i am sorry about that. Here is my question;

I am trying to code an addon module for WHMCS 5 and i want to use bootstrap modal windows in my addon's pages. I am trying to add css and js lines in to the main page of my addon. I want to put them inside the head tag by coding, i do not want to change the template file and i know that it is possible to do this because "WHMCS's Project Planner" module is doing this successfully. I can see that in the source codes of pages.

When i looked into the admin template's "header.tpl" file, there are two smarty codes. {headoutput} and {headeroutput}. They are positioned like below;

<head>
  {headoutput}
</head>
<body>
  {headeroutput}

I have made lots of research about how to send my code to {headoutput} by my module .php file. If anybody knows how to do this, please i need help very much.

Your help is very appreciated. Best Regards, Caner

I have found the solution for reading more documents in WHMCS Documentation and some other places.

First of all as i learnt, after WHMCS 4, developers changed some rules and WHMCS's {headoutput} and {headeroutput} smarties in the templates are not directly editable by the code anymore. WHMCS uses Hooks for adding user codes between special html blocks. And here is the solution about my problem.

Doc. Ref. 1: http://docs.whmcs.com/Hooks
Doc. Ref. 2: http://docs.whmcs.com/Hooks:System

After we did the essential things to create an addon module, we are creating a new file in the module folder named "hooks.php". WHMCS is including this file directly, without any decleration to include, in to our module. In the "hooks.php" we need to create a hook function, explained as in the Doc. Ref. 1. Your function does not need to have a special name but WHMCS developer advices you to use a hierarchy like starting with "hook_", followed by the filename, and then the particular action or task that hook is performing. For example;

function hook_youraddonmodule_adminHeadBlock($vars) {
    //Here is my custom code below
    $headoutput = '<link href="../includes/jscript/css/bootstrap.min.css" rel="stylesheet">';
    return $headoutput;
}

After you name the function, you must type your code between the curly braces that according to your needs. I put bootstrap css file link that i wanted to be included by all my module pages' head blocks. We declared a hook function and then we need to prepare it to be used by WHMCS's predefined hook places as explained int the Doc. Ref. 2. To put the code between head block we have to use "AdminAreaHeadOutput" hook decleration. Here is the code that i used;

// Define Client Login Hook Call
add_hook("AdminAreaHeadOutput",1,"hook_youraddonmodule_adminHeadBlock");
This definition means that we have added a hook to admin area head output and it's priority is first (1). Actually i do not know why we need a priority about hooks and i did not made a research about it but if it has done, there must be an advantage of it :) Now all you need to save the hook file and upload it to your server. All done. I hope it helps the people who is looking for this kind of tricks.

Update:

I have recognized that, when you create a hook and activate it with your module in your admin area, it applies to all admin pages so it can break some of whmcs's standart javascripts and styles. If you want the hook only work for your own module, you should add a code like below for preventing your own codes to be applied in all admin area pages.

$moduleName = $_GET['module'];
if($moduleName == "yourmodulename"){
    return $headoutput;
}

Regards,
Caner.

评论(0)

当前没有评论,还不快来留下第一个脚印吧


Copyright 2021 三三世界-百宝箱. All Rights Reserved.

最新评论

  • 三三

    @Doug Shume it's ok for me , you can post here.

  • refugiaguenther

    Saved as a favorite, I like your website!

  • josefa

    If some one wishes to be updated with hottest technologies after that he must be visit this site and be up to date daily.

  • Penzu

    Heello would you mind sharing which blog platform you're using? I'm planning to start my own blog in the near future but I'm having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then moost blogs and I'm looking for something completely unique. P.S Apologies forr being off-topic butt I had to ask!

  • Yupoo Fendi

    Thanks to my father who shared with me regarding this webpage, this website is genuinely amazing.

  • Doug Shume

    Hi, I have an overflow of customers that I'd like to send to you but I want to make sure you can handle more leads, let me know if you'd like me to send you more info.

  • SuperWind

    zh.us.to 有效
    kms.03k.org 有效
    kms.chinancce.com
    kms.shuax.com 有效
    kms.dwhd.org 有效
    kms.luody.info 有效
    kms.digiboy.ir 有效
    kms.lotro.cc 有效
    www.zgbs.cc 有效
    cy2617.jios.org 有效

  • 三三

    @         权限问题,试试sudo 再加命令。

  •         

    你好提示Permission denied 怎么办啊

日历

2024年05月

   1234
567891011
12131415161718
19202122232425
262728293031 

文章目录

上一张 下一张