Customizing and Extending Sngine: How to Create Custom Pages in Sngine

1
145
0

Sngine is a dynamic platform built for community-driven websites, allowing flexibility for developers to create new features or pages to suit their requirements. This tutorial will provide an updated, step-by-step approach to creating static and dynamic pages in Sngine. The examples have been refined for better functionality and adherence to core patterns.


Understanding Sngine’s File and Folder Structure

Before creating a custom page, it’s important to understand Sngine’s directory structure:

  1. /content/themes/: Contains themes and their associated templates.
  2. /includes/: Handles core controllers, models, and configuration files.
  3. includes/ajax/FOLDER NAME: Used for processing AJAX requests.
  4. /content/languages/: Stores language files for multi-language support.
  5. /themes/template/default/IMAGES & CSS folders: Holds CSS, and static images.

Part 1: Creating a Static Page

Example: Adding an "About Us" Page

Step 1: Create a Template File

  • Navigate to: /content/themes/default/templates/.
  • Create a new file named about_us.tpl
  • Create the smarty controller file in the root name is as aboutus.php

Step 2: Register the Route

  • Open /.htacess.php.
  • Add a route for the new page:
 
RewriteRule ^aboutus/?$ aboutus.php [L,QSA]
 

Step 3: Test the Page

  • Visit the URL: https://yourwebsite.com/aboutus.

Part 2: Creating a Dynamic Page

Step 1: Controller Function

  • Create your Open /aboutus.php.
  • Add the following function:
php
Copy code

<?php

/**
 * About Us
 * 
 * @package Sngine
 * @author Zamblek
 */

// fetch bootloader
require('bootloader.php');

// check if about us feature is enabled
if (!$system['aboutus_enabled']) {
  _error(404);
}

// user access
if (!$system['system_public']) {
  user_access();
}

try {
  // set the default view
  $_GET['view'] = (isset($_GET['view'])) ? $_GET['view'] : '';

  switch ($_GET['view']) {
    case '':
      // static About Us content
      $about_us_content = "
        Welcome to [Your Community Name]! We are dedicated to creating a platform where users can share, connect, and grow together. Our mission is to provide an engaging and supportive environment for all members.
      ";

      // assign variables
      $smarty->assign('about_us_content', $about_us_content);

      // page header
      page_header(__("About Us") . ' | ' . __($system['system_title']), __($system['system_description_aboutus']));
      break;

    default:
      _error(404);
      break;
  }

  // get ads for the page
  $ads = $user->ads('aboutus');
  /* assign variables */
  $smarty->assign('ads', $ads);

  // assign view
  $smarty->assign('view', $_GET['view']);
} catch (Exception $e) {
  _error(__("Error"), $e->getMessage());
}

// page footer
page_footer('aboutus');

Step 2: Create the Template

  • Navigate to: /content/themes/default/templates/.
  • Paste the following code in aboutus.tpl:
html
Copy code

{include file='_head.tpl'}
{include file='_header.tpl'}

<!-- page header -->
<div class="page-header">
  <img class="floating-img d-none d-md-block" src="{$system['system_url']}/content/themes/{$system['theme']}/images/headers/undraw_about_us.svg">
  <div class="circle-2"></div>
  <div class="circle-3"></div>
  <div class="{if $system['fluid_design']}container-fluid{else}container{/if}">
    <h2>{__("About Us")}</h2>
    <p class="text-xlg">{__($system['system_description_aboutus'])}</p>
  </div>
</div>
<!-- page header -->

<!-- page content -->
<div class="{if $system['fluid_design']}container-fluid{else}container{/if} mt20 sg-offcanvas">
  <div class="row">
    <!-- left panel -->
    <div class="col-md-4 col-lg-3 sg-offcanvas-sidebar">
      <!-- optional side content -->
      <div class="card">
        <div class="card-body">
          <h5>{__("Quick Links")}</h5>
          <ul class="side-nav">
            <li>
              <a href="{$system['system_url']}">{__("Home")}</a>
            </li>
            <li>
              <a href="{$system['system_url']}/pages">{__("Pages")}</a>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <!-- left panel -->

    <!-- right panel -->
    <div class="col-md-8 col-lg-9 sg-offcanvas-mainbar">
      <!-- about us content -->
      <div class="card">
        <div class="card-body">
          <h3 class="mb20 text-center">{__("Our Mission")}</h3>
          <p class="text-muted">
            {$about_us_content}
          </p>
        </div>
      </div>

      {include file='_ads.tpl'}
    </div>
    <!-- right panel -->
  </div>
</div>
<!-- page content -->

{include file='_footer.tpl'}

Step 4: Test the Page


Part 3: Enhancements and Best Practices, if you wish it to be multilingual

Multi-Language Support

  • Add new language variables in /content/languages/english.php:
php
 
 
$lang['about_us'] = "About Us"; $lang['top_contributors'] = "Top Contributors"; $lang['points'] = "Points";
  • Use language variables in your templates:
html
Copy code
<h1>{$lang.top_contributors}</h1> <p>{$lang.points}: {$contributor.user_points}</p>

 


Conclusion

Creating and extending custom pages in Sngine allows for unparalleled flexibility. By leveraging static and dynamic pages, AJAX, and multi-language support, you can create feature-rich pages that enhance your user experience. Following the steps outlined here ensures a professional, scalable, and SEO-optimized approach.

Love
1
Αναζήτηση
Προωθημένο
Κατηγορίες
Διαβάζω περισσότερα
Community Building
How to Build an Engaged Online Community Using Sngine
In the fast-paced world of social networking, building an engaged and loyal online community is...
από MakeMyTheme Admin 2025-01-03 22:26:59 0 238
Community Building
How to Build Regional Communities on Sngine with Multi-Language Support
Reach global audiences by enabling localization. The internet connects billions of people...
από MakeMyTheme Admin 2025-01-04 11:04:02 0 299
Community Building
Building Strong Group Identities on Sngine: Strategies to Foster Loyalty Within Niche Groups
Sngine, a robust social networking script, offers immense potential for creating tightly-knit...
από MakeMyTheme Admin 2025-01-03 23:55:09 0 242
Community Building
Building a Marketplace Community with Sngine
Creating a thriving marketplace community requires more than just listing products or...
από MakeMyTheme Admin 2025-01-03 23:25:44 0 250
Monetization and Business
Earning Through Sponsored Posts on Sngine: A Comprehensive Guide
Monetizing your Sngine platform through sponsored posts is one of the most effective ways to...
από MakeMyTheme Admin 2024-12-31 13:21:59 0 295