Zid Docs
Merchant APIApp APIThemes
Merchant APIApp APIThemes
Help Center
Slack
  1. Getting Started with Zid Themes
  • 🚨 Important Update: Zid Themes
  • Landing Page Development
  • Getting Started with Zid Themes
    • Introduction to Theme Development
    • Manage your Themes
    • Building Themes in Zid
    • Theme File Structure
    • Twig Syntax and Features
    • Zid Theme Packager
  • Templates
    • Layout
    • Home Page
    • Products
    • Cart
    • Store Language and Currency
  • Settings Schema
    • Text
    • Number
    • Text-Area
    • Select
    • Radio Buttons
    • Checkbox
    • Range
    • Color
    • Image
    • Product
    • Category
    • List
    • Fieldset
  • Code Snippets
    • Apple Pay Quick Checkout
    • Custom CSS Injection
    • Displaying the Store's Business Center Logo
    • Customizing Copyright Text
    • Store's Main Navigation Menu
    • Customer Wishlist
    • Products
      • Products Badges
      • Product Ratings
      • Remaining Product Stock
      • Sold Items Count
      • Product Filtration by Attributes
      • Grouped Products
      • Product Questions & Answers
      • Product Restock Notfication
    • SEO
      • Images alt text
      • Themes SEO Marketing Tags
    • Marketing
      • Metafields
      • Gift Feature
      • Loyalty Program
  • Zid Themes Library: API Integration
    • Products
    • Product Categories
    • Cart
    • Blog
    • Customer
    • Store Settings
  • Data Reference
    • Locals
    • Store
    • Cart
    • Product
    • Products List
    • Category
    • Categories List
    • Session
    • FAQs
    • Customer
    • Blogs
    • Page
    • Main Menu
    • Main Navigation Menu
    • Request
    • Orders
    • Addresses
    • Store Payment Methods
    • Store Shipping Methods
    • Store Banks
    • Asset URL
    • Header Meta Tags
    • Loyalty pogram Wallet
  • Themes CLI
    • CLI Authentication
    • Theme Create
    • Theme Package
    • Theme Update
    • Themes List
    • Theme Preview
  1. Getting Started with Zid Themes

Twig Syntax and Features

In this section of the Zid Themes Documentation, we delve into the heart of theme customization: the Twig template engine. Twig offers a powerful and flexible syntax for embedding logic and data into your theme's design. This guide will walk you through the essential syntax, tags, functions, and filters you'll need to create dynamic themes.

Understanding the Basics of Twig#

Twig simplifies the infusion of data into templates using two primary syntax forms:
1.
{{ ... }}: This notation is used to display the content of variables.
2.
{% ... %}: This structure is employed to execute logic-based operations such as conditions and loops.

Essential Twig Tags#

Zid supports a subset of Twig's tags to maintain simplicity and performance. Below are the tags available for use in your themes:
extends
block
include
for
if, elseif, else
set

Extending Templates with extends and block#

Twig's template inheritance feature is instrumental in building a base layout, which can then be extended by child templates for customization. Here's an illustrative example of how to use the extends and block tags within a Zid theme:
In this example, the content block in home.twig will replace the corresponding content block within layout.twig. This pattern of inheritance ensures that you can maintain consistent design elements across different pages while customizing content as needed.
Remember that you can also include additional scripts or API calls like zidapi_script within your templates to enhance functionality or track analytics.
Now here is an example of a base layout file in Twig, layout.twig, and how it is structured:
This base layout can then be extended by child templates, which can override specific blocks such as title, content, and footer.

Including Sub-templates with include#

The include tag allows you to incorporate other templates into the current one, similar to a 'copy-paste' action:

Conditional Logic with if, elseif, else and endif#

Twig's if statement allows you to conditionally display content. It can be combined with elseif and else for more complex conditions:

Variable Assignment with set#

Define or modify variables within your templates using the set tag:

Twig Filters#

Filters in Twig modify the content of variables before they are used. Zid supports the following filters:
escape: Ensures the output is safe to render by escaping HTML characters.
length: Returns the number of items in a sequence or characters in a string.
raw: Outputs raw, unescaped data.

Twig Functions#

Functions perform complex operations on variables. Zid provides these functions for your templates:
range: Generates a sequence of numbers.
include: Incorporates other templates.
For a comprehensive understanding and in-depth technical details of Twig, explore official Twig 3.x documentation.
Modified at 2024-07-28 14:52:55
Previous
Theme File Structure
Next
Zid Theme Packager
Built with