Jump to content

How to include an articles in the WHMCS custom page?


Lorraine1996

Recommended Posts

14 minutes ago, brian! said:

an article in what sense ? what is the source of the article content ??

Thank you for responding!
I would like to include a specified knowledge base article in the customization page so that the article can be edited when content needs to be updated without having to modify the customization page.

Link to comment
Share on other sites

56 minutes ago, brian! said:

an article in what sense ? what is the source of the article content ??

Specifically, I want to create a TOS page. tos content written in a knowledge base article.

The reason for using custom pages is that I can use a better URL for the TOS page and I can easily modify the style of the page.

This way, if you need to modify the TOS content in the future, you only need to edit the knowledge base article and not the .tpl file on the customization page.

Its ideal workflow would look like this.

Custom pages -> corresponding .tpl file -> include a specified knowledge base article

Link to comment
Share on other sites

On 11/05/2020 at 13:27, Lorraine1996 said:

Specifically, I want to create a TOS page. tos content written in a knowledge base article.

the .php would be along the lines of...

<?php
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;
define('CLIENTAREA', true);
require __DIR__ . '/init.php';
$ca = new ClientArea();
$ca->setPageTitle(Lang::trans('ordertos'));
$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('tos.php', Lang::trans('ordertos'));
$ca->initPage();
$kbarticle = Capsule::table('tblknowledgebase')->where('id','33')->value('article');
$ca->assign('terms', $kbarticle);
$ca->setTemplate('tos');
$ca->output();

the '33' is the id value of your kb article that contains your ToS text...

q7ZmMw5.png

and then the tos.tpl template needs to contain {$terms} - that's it!

{$terms}

you might need to play with additional styling in the template file depending on your site or additional styling needs, but if the .php file finds the specified article, then the text will be displayed in the page...

UKBUANv.png

Link to comment
Share on other sites

8 hours ago, brian! said:

the .php would be along the lines of...


<?php
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;
define('CLIENTAREA', true);
require __DIR__ . '/init.php';
$ca = new ClientArea();
$ca->setPageTitle(Lang::trans('ordertos'));
$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('tos.php', Lang::trans('ordertos'));
$ca->initPage();
$kbarticle = Capsule::table('tblknowledgebase')->where('id','33')->value('article');
$ca->assign('terms', $kbarticle);
$ca->setTemplate('tos');
$ca->output();

the '33' is the id value of your kb article that contains your ToS text...

q7ZmMw5.png

and then the tos.tpl template needs to contain {$terms} - that's it!


{$terms}

you might need to play with additional styling in the template file depending on your site or additional styling needs, but if the .php file finds the specified article, then the text will be displayed in the page...

UKBUANv.png

Thanks! It worked perfectly!

Link to comment
Share on other sites

9 hours ago, brian! said:

the .php would be along the lines of...


<?php
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;
define('CLIENTAREA', true);
require __DIR__ . '/init.php';
$ca = new ClientArea();
$ca->setPageTitle(Lang::trans('ordertos'));
$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('tos.php', Lang::trans('ordertos'));
$ca->initPage();
$kbarticle = Capsule::table('tblknowledgebase')->where('id','33')->value('article');
$ca->assign('terms', $kbarticle);
$ca->setTemplate('tos');
$ca->output();

the '33' is the id value of your kb article that contains your ToS text...

q7ZmMw5.png

and then the tos.tpl template needs to contain {$terms} - that's it!


{$terms}

you might need to play with additional styling in the template file depending on your site or additional styling needs, but if the .php file finds the specified article, then the text will be displayed in the page...

UKBUANv.png

A problem was just discovered. If multiple language versions of a knowledge base article exist, it does not seem to be able to display the corresponding version based on the language chosen by the user.
May I ask if this problem can be solved?

Link to comment
Share on other sites

9 hours ago, Lorraine1996 said:

A problem was just discovered. If multiple language versions of a knowledge base article exist, it does not seem to be able to display the corresponding version based on the language chosen by the user.

and you're intending to make your ToS translated in different languages ?

11 hours ago, Lorraine1996 said:

May I ask if this problem can be solved?

yes...

<?php
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;
define('CLIENTAREA', true);
require __DIR__ . '/init.php';
$ca = new ClientArea();
$ca->setPageTitle(Lang::trans('ordertos'));
$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('tos.php', Lang::trans('ordertos'));
$ca->initPage();
$kbarticleid = 38;
if ($ca->isLoggedIn()) {
	$language = Capsule::table('tblclients')->where('id',$ca->getUserID())->value('language');
} else {
	$language = $_SESSION['Language'];
}
$kbarticle = Capsule::table('tblknowledgebase')->where('parentid',$kbarticleid)->where('language',$language)->value('article');
if (empty($kbarticle)) {
	$kbarticle = Capsule::table('tblknowledgebase')->where('id',$kbarticleid)->value('article');
}
$ca->assign('terms', $kbarticle);
$ca->setTemplate('tos');
$ca->output();

so the way this works now is that the page will try to get the ToS article in the current WHMCS language... if no article exists in the current or chosen language, it will show the default language version.

u3HICnJ.png

Link to comment
Share on other sites

14 hours ago, brian! said:

and you're intending to make your ToS translated in different languages ?

yes...


<?php
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;
define('CLIENTAREA', true);
require __DIR__ . '/init.php';
$ca = new ClientArea();
$ca->setPageTitle(Lang::trans('ordertos'));
$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('tos.php', Lang::trans('ordertos'));
$ca->initPage();
$kbarticleid = 38;
if ($ca->isLoggedIn()) {
	$language = Capsule::table('tblclients')->where('id',$ca->getUserID())->value('language');
} else {
	$language = $_SESSION['Language'];
}
$kbarticle = Capsule::table('tblknowledgebase')->where('parentid',$kbarticleid)->where('language',$language)->value('article');
if (empty($kbarticle)) {
	$kbarticle = Capsule::table('tblknowledgebase')->where('id',$kbarticleid)->value('article');
}
$ca->assign('terms', $kbarticle);
$ca->setTemplate('tos');
$ca->output();

so the way this works now is that the page will try to get the ToS article in the current WHMCS language... if no article exists in the current or chosen language, it will show the default language version.

u3HICnJ.png

Fantastic, thank for your answers!

Link to comment
Share on other sites

  • 2 weeks later...
On 5/13/2020 at 9:08 PM, brian! said:

and you're intending to make your ToS translated in different languages ?

yes...


<?php
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;
define('CLIENTAREA', true);
require __DIR__ . '/init.php';
$ca = new ClientArea();
$ca->setPageTitle(Lang::trans('ordertos'));
$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('tos.php', Lang::trans('ordertos'));
$ca->initPage();
$kbarticleid = 38;
if ($ca->isLoggedIn()) {
	$language = Capsule::table('tblclients')->where('id',$ca->getUserID())->value('language');
} else {
	$language = $_SESSION['Language'];
}
$kbarticle = Capsule::table('tblknowledgebase')->where('parentid',$kbarticleid)->where('language',$language)->value('article');
if (empty($kbarticle)) {
	$kbarticle = Capsule::table('tblknowledgebase')->where('id',$kbarticleid)->value('article');
}
$ca->assign('terms', $kbarticle);
$ca->setTemplate('tos');
$ca->output();

so the way this works now is that the page will try to get the ToS article in the current WHMCS language... if no article exists in the current or chosen language, it will show the default language version.

u3HICnJ.png

May I ask one more question? Is it possible to use the article title as a source for the page title? This way the title of the page also supports multilingualism.

Link to comment
Share on other sites

5 hours ago, Lorraine1996 said:

May I ask one more question? Is it possible to use the article title as a source for the page title? This way the title of the page also supports multilingualism.

technically, isn't that two questions?? .... but i'm having a Ask One Get One Free offer this morning, so you're in luck. ☺️

you should only need to tweak the queries a little to get the kb title, and then call the setting of the pagetitle after you have done that...

<?php
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;
define('CLIENTAREA', true);
require __DIR__ . '/init.php';
$ca = new ClientArea();
$ca->initPage();
$kbarticleid = 38;
if ($ca->isLoggedIn()) {
	$language = Capsule::table('tblclients')->where('id',$ca->getUserID())->value('language');
} else {
	$language = $_SESSION['Language'];
}
$kbarticle = Capsule::table('tblknowledgebase')->where('parentid',$kbarticleid)->where('language',$language)->select('title','article')->first();
if (empty($kbarticle)) {
	$kbarticle = Capsule::table('tblknowledgebase')->where('id',$kbarticleid)->select('title','article')->first();
}
$ca->setPageTitle($kbarticle->title);
$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('tos.php', $kbarticle->title);
$ca->assign('terms', $kbarticle->article);
$ca->setTemplate('tos');
$ca->output();
Link to comment
Share on other sites

3 hours ago, brian! said:

technically, isn't that two questions?? .... but i'm having a Ask One Get One Free offer this morning, so you're in luck. ☺️

you should only need to tweak the queries a little to get the kb title, and then call the setting of the pagetitle after you have done that...


<?php
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;
define('CLIENTAREA', true);
require __DIR__ . '/init.php';
$ca = new ClientArea();
$ca->initPage();
$kbarticleid = 38;
if ($ca->isLoggedIn()) {
	$language = Capsule::table('tblclients')->where('id',$ca->getUserID())->value('language');
} else {
	$language = $_SESSION['Language'];
}
$kbarticle = Capsule::table('tblknowledgebase')->where('parentid',$kbarticleid)->where('language',$language)->select('title','article')->first();
if (empty($kbarticle)) {
	$kbarticle = Capsule::table('tblknowledgebase')->where('id',$kbarticleid)->select('title','article')->first();
}
$ca->setPageTitle($kbarticle->title);
$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('tos.php', $kbarticle->title);
$ca->assign('terms', $kbarticle->article);
$ca->setTemplate('tos');
$ca->output();

Thank you Brian ! 

I have discovered an irrelevant problem. If the page requires login to view, the login page will not display the title.

kwaOW5GRnFbe.png.9d5340e372e53136850c744cb84b389c.png

Edited by Lorraine1996
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated