Module Website
Website | |
---|---|
Numero/ID of module | Website |
User doc. of module | This page |
Developer doc. of module | Module Website (developer) |
Introduction
The module website add a CMS (Content Management System) inside Dolibar ERP CRM. You can create your own website inside Dolibarr, publish your website using an external web server like Apache and NGinx and reuse any data from your ERP CRM into your website.
Installation
This module is included with the Dolibarr distribution, so there is no need to install it.
Configuration
To use this module, you must first enable it using an administrator account, via the menu option "Home - Setup - Modules".
Choose the tab where the module is listed. Then click on "Activate".
The module is now activated.
If a cog icon appears on module thumb or at end of the line of the module, click on it to access the setup page specific to the module.
Create a new website
Go on top menu "Website" then use the button "New website" to initialize a new website. You are ready to add your fist page.
Add a new page / container
To add your first page, you can start a page from scratch or import an existing website/template that you can modify later.
Import a website template
This is the fastest way to get a website ready to publish. Click on "Import website". Choose your template or upload a template from one of the template market place or provided by your web agency.
Create a new page from scratch
Just click on the button "Add page/container". Fill the meta information and "Save". Now you can click on "Edit source" to add your HTML content. ...
Include dynamic content into a page
One of the most interesting feature of Dolibarr CMS is that you can include dynamic content by adding PHP code, anywhere on your web site. Only restricted people can do this because they need the permission "Add dynamic content" to be allowed to do that. Adding dynamic content is as easy as developping in PHP. Just add the <?php and ?> tags. You can use, in your dynamic code, any of the following predefined global variable (they are already initialized and populated):
$conf, $user, $db, $mysoc, $website, $websitepage, $weblangs, $pagelangs
Get properties of your company
This is an example of dynamic content to get the name of your company:
<?php echo $mysoc->name; ?>
Get properties of the web page
This is another example of dynamic content to get meta data of a container/page:
__(Title)__ : <?php echo $websitepage->title; ?><br>
__(Description)__ : <?php echo $websitepage->description; ?><br>
__(Keywords)__ : <?php echo $websitepage->keywords; ?><br>
__(DateCreation)__ : <?php echo dol_print_date($websitepage->date_creation, 'dayhour', $weblangs); ?><br>
Add the content of a page/container into another page/container
Including a container into a parent container allows to move some content (text or html) of a page into a sub-page. So you can include it on several pages. Changing the content of the subpage will be propagated on any page that include the sub-page. It is similar to using the "Templates" with Mediawiki or using the #include in C++.
To include the content of a sub-page/sub-container into another one, just add this in the source of your page, where you want to have the sub-content included:
<?php includeContainer('alias_of_container_to_include'); ?>
Add a redirection to another page
If you want to make a redirection to another page, you can add the following code into the source of the page:
<?php redirectToContainer('alias_of_container_to_redirect_to'); ?>
or
<?php redirectToContainer('alias_of_container_to_redirect_to', '', 0, 0, $array_of_get_params); ?>
Other tips
To include an image stored into the medias directory (directory open for public access), use the relative path starting with /medias, example:
<img src="/medias/image/myimagepath/filename.ext">
For an image shared with a share link (open access using the sharing hash key of file), use the wrapper:
<img src="/viewimage.php?hashp=12345679012...">
To get the URL of the image of a PHP object, use
<img src="<?php print getImagePublicURLOfObject($object, 1, "_small") ?>">
To get the URL of an image inside a html content of an article, use
<img src="<?php print getImageFromHtmlContent($$htmlcontent, 1) ?>">
Example of dynamic code: Latest Blog post
This is an example of a section to show the list of latest 5 active articles (container with type "blogpost"), in english, that contains the keyword "mykeyword".
<!-- Blog list -->
<section id="sectionnews" contenteditable="true" class="main section-50 section-md-50 section-md-bottom-50">
<h2>Latest Blog posts</h2>
<div class="center">
<?php
$keyword = 'mykeyword';
$weblangs->loadLangs(array("main"));
$arrayofblogs = $websitepage->fetchAll($website->id, 'DESC', 'date_creation', 5, 0, array('type_container'=>'blogpost', 'keywords'=>$keyword, 'status'=>'1', 'lang'=>'en'));
if (is_numeric($arrayofblogs) && $arrayofblogs < 0) {
print '<div class="error">'.$weblangs->trans($websitepage->error).'</div>';
} elseif (is_array($arrayofblogs) && ! empty($arrayofblogs)) {
$fuser = new User($db);
foreach($arrayofblogs as $blog) {
print '<div class="row justify-content-sm-center row-40">';
print '<div class="container blog-box centpercent" style="padding: 20px; transition: .3s all ease;">';
print '<a href="'.$blog->pageurl.'.php">';
print '<div class="post-boxed-img-wrap"><img src="'.($blog->image ? 'viewimage.php?modulepart=medias&file='.$blog->image : 'medias/image/'.$website->ref.'/calendar.svg"').'" alt="" width="120"></div>';
print '<div class="post-boxed-caption">';
print '<div class="post-boxed-title font-weight-bold">'.$blog->title.'</div>';
print '<ul class="list-inline list-inline-dashed text-uppercase">';
print '<li>'.dol_print_date($blog->date_creation, 'daytext', 'tzserver', $weblangs).'</li>';
$fuser->fetch($blog->fk_user_creat);
print '<li><span>by<span> <span class="text-primary">'.($fuser->firstname?$fuser->firstname:$fuser->login).'</span></span></li>';
print '</ul>';
print '</div>';
//includeContainer($blog->pageurl);
print '<span class="nohover">'.$blog->description.'</span>';
print '</a>';
print '</div>';
print '</div>';
}
} else {
print $weblangs->trans("NoArticlesFoundForTheKeyword", $keyword);
}
?>
</div>
</section>
Example of dynamic code: List your products
This is an example to show the list of products in your database:
<!-- Blog list -->
<section id="sectionproducts" contenteditable="true" class="main section-50 section-md-50 section-md-bottom-50">
<h2>Liste des produits</h2>
<div class="center">
<?php
$weblangs->loadLangs(array("main"));
$sql = 'SELECT rowid, ref FROM '.MAIN_DB_PREFIX.'product WHERE tosell > 0';
$resql = $db->query($sql);
if ($resql) {
$num_rows = $db->num_rows($resql);
$i = 0;
while ($i < $num_rows) {
$obj = $db->fetch_object($resql);
print $obj->ref."<br>\n";
$i++;
}
} else {
print $weblangs->trans("NoRecordFound");
}
?>
</div>
</section>
Read another remote Dolibarr database
Just create a remote database connection and then, use this one for your SQL requests
global $dbmaster;
$dbmaster = getDoliDBInstance('mysqli', 'myserver', 'userread', 'abcdef', 'databasename', 3306);
$confmaster = new Conf();
if ($dbmaster) $confmaster->setValues($dbmaster);
Note: You can also decide to use the APIs.
Create a custom 404 page
To create a custom 404 page, just create a common empty page with the name "404" and the type "page". Then edit the HTML content of the page with the content of your choice, and add at the end the page
<?php http_response_code(404); ?>
Then you must edit your web server setup to tell to use this page as the 404 page. For example with Apache, add into your virtual host configuration:
ErrorDocument 404 /404.php
Deploy | Publish your website
To make your website live, you can click on the link "Deploy/Text my website". A popup will show you instructions to setup the web server, like Apache, so you can make your website live on the Internet. When a website is lived, it is not necessary to have Dolibarr application live, but the database must still remain started.
Note: It is not possible to have your website and Dolibarr backoffice (that is itself a website tool) using the exactly same domain name. Indeed, it is thanks to the domain name that the web server (like Apache, Nginx, ...) knows where to redirect the request (The Dolibarr Backoffice itself or the websote built by the CMS of Dolibarr). But you can choose the beginning of the name to differentiate them.
For example, you can use:
- http://admin.example.com for the Dolibarr backoffice tool and
- http://www.example.com for the first Website edited by the CMS feature.
- http://www2.example.com for the second Website edited by the CMS feature.
- http://www.example2.com for the third Website edited by the CMS feature.