UAP 4 Documentation - AddingLibs
This tutorial will explain how use common Libraries within your pages. It is easy to add Sweets, Views, Comments, and more to your custom pages.
Getting Started
In this tutorial we will expand on the services page. We will add a Sweets button, a Views display, and a Comments section.

We will continue to use the Services page in this example. http://www.mywebsite.com/Services
Adding Libraries to the View
There is no need to edit the Controller at this time. We will only be editing the Services View file.

/app/Views/Services/Services.php - View File

Building the View
We will want to include the Libs that we are going to use. We want to add the following code to the top of the Services View file.

<?php
	use Libs\PageViews,
	Libs\Sweets,
	Libs\Comments;
?>
Now that we have included the files needed we can add the code needed to display the different Libraries.

Let's start with the Views Library. To log and display the page views we need to add the following code where we want the button displayed. You can add style as wanted, but for now we are just going to keep it plain and simple.

Total Page Views: <?php echo PageViews::views(true, 1, "Services"); ?>
We can add a Sweets button near the Views display. Like before it can be placed where wanted.

<?php echo Sweets::getSweets(1, "Services"); ?>
<?php echo Sweets::displaySweetsButton(1, "Services", $current_userID, 0, "Services"); ?>
We can now add the comment to the Services View. This can be placed where you want it, however it is designed to go in the card footer. We will place the Comments Library in the card footer in this example. The Comments Plug-In is not setup to display the new page's comments, so we set the 7th var in the display comments function to "view_comments". That will let it know to display all comments on this page.

<div class="card-footer">
	<?php echo Comments::displayComments(1, "Services", $current_userID, 0, "Services/", null, "view_comments"); ?>
	<?php echo Comments::getTotalComments(1, "Services", 2); ?>
</div>
We now have everything needed to expand our Services page to display Views, Sweets, and Comments. Here is what your Services View file should look like:

<?php
	/* Includes */
	use Libs\PageViews,
	Libs\Sweets,
	Libs\Comments;
?>
<div class="col-12">
	<div class="card mb-3">
		<div class="card-header h4">
			<?php echo $data['title']; ?>
		</div>
		<div class="card-body">
			Total Page Views: <?php echo PageViews::views(true, 1, "Services"); ?><br>
			<?php echo Sweets::displaySweetsButton(1, "Services", $current_userID, 0, "Services"); ?>
			<?php echo Sweets::getSweets(1, "Services"); ?><br>
			Logo Design<br>
			Info about Logo Design...<br>
			<br>
			SEO Optimization<br>
			Info about SEO Optimization...<br>
			<br>
			Site Layout and Design<br>
			Info site layout and design...
		</div>
		<div class="card-footer">
			<?php echo Comments::getTotalComments(1, "Services", 2); ?>
			<?php echo Comments::displayComments(1, "Services", $current_userID, 0, "Services/", null, "view_comments"); ?>
		</div>
	</div>
</div>
If we open the Services page on our site, we should see that everything that we just added is up and working. Now it may not look the way we want, or the buttons may be in a bad locations. They can be placed anywhere in the View file that we like. For more information about UAP Libraries, check the Docs or use the UAP Forum.

UAP 4 Documentation - AddingLibs

Title
Statistics
Last Reply