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

1
168
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
Cerca
Sponsorizzato
Categorie
Leggi tutto
Community Building
The Role of Moderators in Building a Safe and Thriving Community
A safe, inclusive, and thriving community doesn't just happen—it is the result of...
By MakeMyTheme Admin 2025-01-03 23:50:17 0 244
Community Building
The Power of Stories: Sharing User Experiences on Sngine
User stories are the lifeblood of any community, and for platforms built on Sngine, they hold the...
By MakeMyTheme Admin 2025-01-04 10:23:56 0 245
Monetization and Business
How to Set Up and Use Donations on Sngine
Donations are a fantastic way to enable community-driven or non-profit initiatives on your...
By MakeMyTheme Admin 2024-12-31 13:17:25 0 293
Community Building
10 Icebreaker Strategies for New Communities on Sngine to Boost Engagement
Introduction Launching a new community on Sngine is exciting, but the real challenge lies in...
By MakeMyTheme Admin 2025-01-03 22:55:00 0 254
Monetization and Business
Creating a Subscription Model on Your Sngine Platform: A Step-by-Step Guide
With the rise of subscription-based services, implementing a subscription model on your Sngine...
By MakeMyTheme Admin 2024-12-31 11:17:54 0 296