Welcome back to our TotalGPT SaaS website development journey! In this post, we’re diving deep into the implementation of pricing.html and pricing_details.html, using the Total.js View Engine. This is where the magic of dynamic web pages happens, and we’ll guide you step-by-step through the process. This post is tailored for beginners, so even if you’re new to Total.js, you’ll be able to follow along. Let’s get started!
The Total.js View Engine is a lightweight and flexible template engine that works seamlessly within the Total.js framework. It allows developers to create dynamic and responsive HTML pages by combining server-side data with intuitive templates. Its key features include:
By the end of this post, you’ll understand how to:
Routes define how the application handles incoming HTTP requests. Let’s start by reviewing the route definitions in controllers/default.js
:
/pricing/
: This route serves the pricing overview page, displaying all available pricing plans./pricing/{choice}/
: This route serves the details of a specific pricing plan based on the {choice}
parameter in the URL.The pricing
function handles requests for the pricing overview page. Here’s how it works:
CALL('Plan --> list')
: Calls the list
action within the Plan
schema to fetch all pricing plans..reverse()
: Reverses the order of the plans to display them in the desired sequence.$.view('pricing', { plans: plans })
: Renders the pricing.html
view and passes the plans
data to it.This setup ensures that the pricing page dynamically displays all available plans.
The pricing_details
function fetches and renders details for a specific pricing plan. Let’s explore the implementation:
$.params.choice
: Captures the {choice}
parameter from the URL.DATA.read('nosql/plans')
: Fetches plan details from a NoSQL database..fields()
: Selects specific fields for efficiency.$.view('pricing_details', { selectedPlan: plan })
: Renders the pricing_details.html
template with the selected plan’s data.This template displays the list of pricing plans dynamically:
@{ foreach plan in model.plans }
: Iterates over the plans
array passed from the server.@{ if plan.name === 'Standard' }
: Adds a special style for the "Standard" plan.plan.id
.This template displays the details of a selected pricing plan:
model.selectedPlan
: Contains the data for the selected pricing plan, passed from the server.To enhance the visual appeal of the pages, here’s an example of basic CSS:
.pricing-item
: Defines the layout and styling for pricing cards..highlighted
: Highlights special plans, such as the "Standard" plan.By mastering these core concepts, you’ll be equipped to build sophisticated, data-driven web applications using Total.js. In our next post, we’ll explore advanced features of the View Engine, such as partials, nested templates, and optimizing performance. Stay tuned!