Butterfly
  • Butterfly
  • Introduction
  • Changelog
  • Admin Panel
  • Audit Logs
  • Cloud
  • Commands
  • Data Manager
  • Data Types
  • Database
  • Designs
  • Introduction
  • Features
  • File Storage
  • Frontend
  • Generators
  • Helpers
  • Installation
  • Items
  • Migrations
  • Modules
  • Notification
  • Performance
  • Queue
  • Security
  • Settings
  • Smarty Helpers
  • Streams
  • Testing
  • Tutorials
  • Upgrade
  • Usage of Validator
  • Webservice
  • Swagger API Documentation Generator
  • CLI Commands
Powered by GitBook
On this page
  • Email Operations
  • Basic email
  • Template email
  • Approval email
  • SMS
  • File Operations
  • Get file
  • Get file content
  • Delete file
  • Save image
  • Database Operations
  • Listing Query
  • Matrix Query
  • Vector Query
  • Basic query
  • Complex query
  • CRUD operations
  • Value management
  • Excel Operations
  • Filters
  • Array operations
  • String operations
  • Data visualization
  • Table view
  • Configuration and Registry
  • Path handling
  • State Management
  • HTTP Requests
  • User and Permissions
  • GPT Integration
  • URL and Parameters
  • Header
  • Footer

Smarty Helpers

Email Operations

Basic email


<div data-gb-custom-block data-tag="set" data-subject='Important Update'></div>

<div data-gb-custom-block data-tag="set" data-message='Your request has been processed'></div>

{{ sendEmail(recipient, subject, message) }}

Template email


<div data-gb-custom-block data-tag="set" data-template='welcome-email'></div>

{% set vars = {
"username": "John",
"activation_link": "https://example.com/activate"
} %}
{{ sendEmailWithTemplate(recipient, template, vars) }}`

Approval email


<div data-gb-custom-block data-tag="set" data-subject='Approval Required'></div>

<div data-gb-custom-block data-tag="set" data-message='Please review and approve'></div>

{{ sendApprovalEmail(subject, message, 'approval-template', 'email') }}

SMS


<div data-gb-custom-block data-tag="set" data-phone='+905000000'></div>

<div data-gb-custom-block data-tag="set" data-message='Your verification code is 123456'></div>

{{ sendSms(phone, message) }}

File Operations

Get file

{{ getFile(filePath, fileAlias) }}

Get file content

{{ getFileContent(filePath, fileAlias) }}

Delete file

{{ unlinkFile(localPath) }}

Save image


<div data-gb-custom-block data-tag="set" data-0='https://example.com/test.png'></div>

<div data-gb-custom-block data-tag="set" data-fileName='profile.png'></div>

<div data-gb-custom-block data-tag="set" data-alias='avatars'></div>

<div data-gb-custom-block data-tag="set" data-folder='users'></div>

<div data-gb-custom-block data-tag="set"></div>

{{ response.success }}
{{ response.full_path }}

Database Operations

Listing Query


<div data-gb-custom-block data-tag="set"></div>

{{ query
.where('status', 'active')
.orderByDesc('created_at')
.keyToValue('id', 'name')
}}

Matrix Query

{% set matrix = getListingQuery()
.matrix('category', 'subcategory', 'count')
%}

Vector Query

{% set vector = getListingQuery()
.vector('id', 'name', 'email')
%}

Basic query

{% set users = db()
.from('users')
.where('status', 'active')
.get()
%}

Complex query

{% set orders = db()
.from('orders')
.join('users', 'users.id', '=', 'orders.user_id')
.where('orders.status', 'pending')
.whereIn('orders.type', ['retail', 'wholesale'])
.whereBetween('orders.created_at', [startDate, endDate])
.orderByDesc('orders.created_at')
.groupBy('orders.user_id')
.paginate(20, 1)
%}

CRUD operations

{% set result = crud('default')
.table('products')
.insert({
'name': 'New Product',
'price': 99.99,
'status': 'active'
})
%}

Value management


<div data-gb-custom-block data-tag="set" data-columnName='status'></div>

<div data-gb-custom-block data-tag="set" data-value='active'></div>

{{ setValue(columnName, value) }}

<div data-gb-custom-block data-tag="set"></div>

Excel Operations


<div data-gb-custom-block data-tag="set" data-0='Sales Report' data-1='Sales Report'></div>

{{ excel
.sheet('Overview')
.fromArray(data)
.cell('A1', 'Sales Data')
.merge('A1:D1')
.bold('A1:D1')
.width('A', 15)
.alignText('A1', 'center', 'center')
.formatNumber('B2:B10', 2)
.formatCurrency('C2:C10', '$')
.freeze('A2')
.border('A1:D10')
.download('report.xlsx')
}}

Filters

Array operations


<div data-gb-custom-block data-tag="set" data-0='apple' data-1='apple' data-2=', ' data-3='banana'></div>

{{ items|add('orange') }}
{{ items|push('grape') }}
{{ items|count }}
{{ items|chunk(2) }}

String operations

{{ 'Hello World'|truncate(5) }}
{{ 'Product Name'|slug }}
{{ '42.5'|floatVal }}
{{ '42'|intVal }}
{{ 'a,b,c'|explode(',') }}

Data visualization

{% set chartData = {
'January': {'sales': 100, 'costs': 80},
'February': {'sales': 150, 'costs': 100},
'March': {'sales': 200, 'costs': 150}
} %}
{{ chartData|dataset({'January': 'Jan', 'February': 'Feb'})|chart('line') }}

Table view

{% set tableData = [
{'id': 1, 'name': 'John', 'email': 'john@example.com'},
{'id': 2, 'name': 'Jane', 'email': 'jane@example.com'}
] %}
{{ tableData|table({
'id': 'ID',
'name': 'Name',
'email': 'Email'
}, [
'<a href="/edit/<id>" class="btn">Edit</a>',
'<a href="/delete/<id>" class="btn">Delete</a>'
]) }}

Configuration and Registry

{{ 'app.debug'|config }}
{{ 'cache_key'|registry }}
{{ 'user_preferences'|registry(userPrefs) }}

Path handling

{{ path({'alias': 'uploads', 'type': 'file', 'full': true}) }}
{{ imagePath('avatars') }}
{{ filePath('documents') }}

State Management

{{ error_message('Validation failed') }}
{{ confirm('Are you sure?') }}
{{ notValid() }}
{{ validHidden() }}
{{ validRequire('Please fill required fields') }}

HTTP Requests

{{ getRequest(endpoint, options) }}
{{ postRequest(endpoint, vars, options) }}

User and Permissions

{{ currentUser('role_id') }}
{{ hasPermission('edit') }}

GPT Integration


<div data-gb-custom-block data-tag="set" data-0='gpt-4-mini' data-1='gpt-4-mini'></div>

URL and Parameters

{{ currentUrl() }}
{{ getParameter('page', 1) }}
{{ getAllParameters() }}

Header


<div data-gb-custom-block data-tag="block">

</div>

Footer


<div data-gb-custom-block data-tag="block">

</div>
PreviousSettingsNextStreams

Last updated 5 months ago