Building visually appealing web applications

Categories ASP.NET, PHP, Tutorials

When you build a public-facing application you need to make sure it looks sharp. In this article, we'll show you a few ideas of how you can make PHPRunner and ASPRunner.NET projects look unique.

List page grid

Let's start with the grid on the List page. As an example, we will be using a recently updated News template that comes with PHPRunner and ASPRunner.NET. We want to draw attention to the very first element, making it bigger than others.


Luckily, it is fairly easy to implement. Building a custom grid like this only involves a few lines of CSS code. More than that, there is a great Grid by example website that provides all the required CSS code.

1. In the Page Designer proceed to that List page and set grid type to 'vertical-grid'.

2. Under Editor->Custom CSS add the following CSS code.

.r-record-body{
    width:auto !important;
    margin:0px !important;
    padding:3px !important;
    width:auto !important;
}

.r-record-body:first-child {
    grid-column: 1 / 3;
    grid-row: 1 / 3;
}
.r-grid > .r-fluid[data-location="grid"] {
    display: inline-grid;
    grid-template-columns: repeat(4, 24%);
    grid-template-rows: repeat(4, auto);
    justify-content: center;
    align-content: end;
}

This is it. If you now build and run your project, you will see a grid similar to the one on the screenshot above.

Quick filter menu with icons

Take a look at this menu that comes with the Classified template. This is basically a custom filter similar to one that you can see on the left side.

Let's see how you can do something similar in your own project.

1. This menu is database-driven. Here is an example of the clcategory table that powers this menu in the Classified template. This is what kind of data it stores.

Faicon here is a field that holds the name of the icon from Font Awesome. Don't worry, you do not need to enter those names manually, we have built a special dialog that allows users to select an icon. We'll talk about this later in this article.

2. Once you have your categories data ready it is time to insert the menu. Proceed to the List page in the Page Designer and insert a new code snippet above the grid, as appears on the screenshot below.

3. Here is the code you need to use in that snippet

PHP code:

$cats_rs = DB::Select("clcategory");
while($cat = $cats_rs->fetchAssoc()){
	$cat_count_rs = DB::Select("clmain",array("Category" => $cat["CategoryName"] ));
	$cat_count = $cat_count_rs->fetchAssoc();
	if( $cat_count )
		echo "".$cat["CategoryName"]."";
}

C# code

dynamic cat = XVar.Array(), cat_count = null, cat_count_rs = null, cats_rs = null;
cats_rs = XVar.Clone(DB.Select(new XVar("clcategory")));
while(XVar.Pack(cat = XVar.Clone(cats_rs.fetchAssoc())))
{
	cat_count_rs = XVar.Clone(DB.Select(new XVar("clmain"), (XVar)(new XVar("Category", cat["CategoryName"]))));
	cat_count = XVar.Clone(cat_count_rs.fetchAssoc());
	if(XVar.Pack(cat_count))
	{
		MVCFunctions.Echo(MVCFunctions.Concat("", cat["CategoryName"], ""));
}
}

Things you would need to change here:
clcategory - name of the table with categories
clmain - name of the main table
CategoryName - name of category field in categories table
Category - name of the category field in the main table
faicon - name of the field in categories table that stores icon name

The purpose of this code is to display a list of categories with respective icons and make them hyperlinks pointing to all items in the selected categories. A sample link will look like this:

clmain_list.php?page=list&f=(Category~equals~Jobs)

4. Now we need to make it look pretty. For this purpose add the following CSS code

[data-itemid="category_list"] {
    display: flex !important;
    gap: 3px;
}

[data-itemid="category_list"] .category_item {
    flex: auto;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0;
    background: rgba(255, 255, 255, 0.28);
    border: none !important;
    transition: .4s;
    cursor: pointer;
}

[data-itemid="category_list"] .category_item:hover {
    background: white;
}

[data-itemid="category_list"] .category_item .fa {
    margin-bottom: 10px;
    width: 20px;
    height: 20px;
    font-size: 20px;
    color: white;
}

[data-itemid="category_list"] .category_item a {
    color: white;
}

[data-itemid="category_list"] .category_item:hover a,
[data-itemid="category_list"] .category_item:hover .fa {
    color: black;
}

Customizing breadcrumbs

We will be using the breadcrumbs example as it appears on the View page in the News template. We want to display a home icon, category name, and a news title itself.

1. Enable breadcrumbs under Page Designer -> View page -> Options -> Misc

2. Add the following code to View page: Before Display event.

PHP code:

$xt->assign( "breadcrumbs", true );
$xt->assign( "breadcrumb", true );

// link to 'home' 
$xt->assign("crumb_home_link", GetTableLink("newsmain","list"));
$breadcrumb = array();

// link to category
$breadcrumb[] = array("crumb_attrs" => "href='".GetTableLink("newsmain","list")."?f=(Category~equals~".rawurlencode($values["Category"]).")'", "crumb_title_link" => true,"crumb_title" => $values["Category"]);

// article name itself, no link
$breadcrumb[] = array("crumb_attrs" => "", "crumb_title_span" => true,"crumb_title" => $values["Title"]);
$xt->assign_loopsection("crumb", $breadcrumb);

C# code:

xt.assign(new XVar("breadcrumbs"), new XVar(true));
xt.assign(new XVar("breadcrumb"), new XVar(true));

// link to 'home' 
xt.assign(new XVar("crumb_home_link"), (XVar)(MVCFunctions.GetTableLink(new XVar("newsmain"), new XVar("list"))));
breadcrumb = XVar.Clone(XVar.Array());

// link to category
breadcrumb.InitAndSetArrayItem(new XVar("crumb_attrs", MVCFunctions.Concat("href='", MVCFunctions.GetTableLink(new XVar("newsmain"), new XVar("list")), "?f=(Category~equals~", MVCFunctions.RawUrlEncode((XVar)(values["Category"])), ")'"), "crumb_title_link", true, "crumb_title", values["Category"]), null);

// article name itself, no link
breadcrumb.InitAndSetArrayItem(new XVar("crumb_attrs", "", "crumb_title_span", true, "crumb_title", values["Title"]), null);
xt.assign_loopsection(new XVar("crumb"), (XVar)(breadcrumb));

Single record view on the List page

We have two tasks here. First, we want to use an image as a background of the whole record cell, while displaying the text over this image. And second, we want this image to pop up, when we move our mouse over the cell.

1. Set grid type to 'vertical-grid', set records per row to 4. This is how the grid itself is going to look.

2. Image will be only used as a background of the cell. To do so, we set 'View as' type of the image field to 'Custom' and use the following code.

PHP code

$img = my_json_decode($data["news_image"]);  
$value = "";

C# code

dynamic img = XVar.Array();
img = XVar.Clone(MVCFunctions.my_json_decode((XVar)(data["news_image"])));
value = XVar.Clone(MVCFunctions.Concat(""));

3. Now comes the CSS. This code goes to Editor -> Custom CSS area.

.newsmain .list_image {
    background-size: cover;
    background-position: center center;
    position: relative;
    -webkit-transition: 1s;
    -moz-transition: 1s;
    transition: 1s;
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    transform: scale(1);
    -webkit-transform-origin: 50% 100% 0;
    -moz-transform-origin: 50% 100% 0;
    transform-origin: 50% 100% 0;
}
.newsmain .r-record-body .panel-body tbody tr:first-child {
    display: block;
    position: relative;
    /* change the height of the record if you need to */
    height: 210px;
}
/* making the first cell (image) cover the whole record area */
.newsmain .r-record-body .panel-body tbody tr:first-child td{
    width: 100%;
    position: absolute;
}
.newsmain .r-record-body .panel-body tbody tr:first-child td:first-child * {
    height: 210px;
    display: inline-block;
    width: 100%;
    /* this is necessary to make sure image stays inside cell boundaries when enlarged */
    overflow: hidden !important;
}
/* enlarging image when mouse is hovering the cell */
.newsmain .r-record-body:hover .list_image{
    -webkit-transform: scale(1.035);
    -moz-transform: scale(1.035);
    transform: scale(1.035);
}

4. You may have noticed that this CSS uses the prefix .newsmain. The idea is to apply this CSS to a single page only, the List page of the main News table. To achieve this, we also need to add the following code to 'List page: Before Display' event.

PHP code:

$xt->assign("stylename","newsmain"); 

C# code:

xt.assign("stylename", "newsmain");

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *