LayoutHub
  • What is LayoutHub?
  • User guides
    • Support
    • Installation
    • Uninstallation
    • Upgrade/Downgrade
    • FAQs
      • How to remove instagram section from Layouthub
      • What is "Pages limit"?
      • When can I "Edit code"?
      • What about "Save section"?
      • What is " Auto save draft"?
      • What is "Integration Services"?
      • How to set the same font between Shopify and LayoutHub?
      • How to custom font and color on LayoutHub?
      • How to set "Page handle or human url"?
      • Connective Button
      • How to save page without publish it
      • How to change the meta SEO for LayoutHub's page
    • Common Issues
    • Layout Management
      • Create Layouts
      • Design Blocks
      • Export & Import
      • Edit Section Code
      • Edit a Layout
      • Assign a Layout
      • Duplicate a Layout
      • Delete a Layout
    • Section builder
    • LayoutHub pages/templates
      • Home Page
        • Create additional Home Page
        • Make an existing page as home page
        • Restore to default Home Page
        • Customize Shopify Home Page
      • Sub-page
        • Contact Form
      • Product Template
        • Product Detail
        • Related Product
      • Collection Template
      • Blog Templates
      • Article Templates
      • Insert section
    • Pricing Plans
    • Settings
      • General
      • Theme Settings
      • Quickview Settings
      • Swatch color settings
      • Third party Apps
        • Product Review
        • Product Wishlist
    • Trash
    • Sale Tools
    • Referrals
    • Integration
      • Add/Edit Profile
      • Add New Contact
      • Export Contact
      • Mailchimp
      • Hubspot
      • ActiveCampaign
      • GetResponse
      • SendGrid
      • Gmail SMTP
      • Google Sheets
      • Omnisend
      • Klaviyo
      • ConvertKit
    • Tracking & Analytics
    • Layouthub & Shopify
    • Translate Apps
    • Recommend apps
      • Avada SEO Optimization
      • Ali Reviews ‑ Product Reviews
      • Ryviu: Product Reviews App UGC
      • Quick View by Secomapp
      • LAI AliExpress Reviews
      • Judge.me Product Reviews
      • Growave - Loyalty, Wishlist, Reviews UGC
      • Opinew Product Reviews
    • Refund Policy
    • Instagram token
  • Development
    • Getting started
    • Tools
      • LayoutHub Kit (for LayoutHub developers only)
      • LayoutHub Kit Extension for Visual Studio Code
    • Layout Structure
    • Reference
      • Engine syntax
        • Deprecated: March 2020
        • Chuẩn template mới - LayoutHub Editor V4
      • Create a section
      • Components
      • Liquid in section
      • Javascript in section
      • Register vendors
      • Settings.js
        • Call-to-action
        • Text
        • Textarea
        • Text Editor
        • Dropdown
        • Checkbox list
        • Checkbox radio
        • Toggle
        • Number slider
        • Number
        • Single image
        • Image library
        • Color picker
        • Icon picker
        • Font picker
        • Background
        • Picker
        • Group fields
Powered by GitBook
On this page

Was this helpful?

  1. Development
  2. Reference
  3. Engine syntax

Chuẩn template mới - LayoutHub Editor V4

Tiêu chuẩn và cú pháp mới cho việc xây dựng layout.

PreviousDeprecated: March 2020NextCreate a section

Last updated 4 years ago

Was this helpful?

Sử dụng cấu trúc template của Vuejs

Từ phiên bản 4.0 LayoutHub Editor chuyển sang sử dụng bộ render của . Điều đó đồng nghĩa các nhà phát triển layout có thể sử dụng hầu hết các cú pháp của để xây dựng và phát triển các layout cho nền tảng LayoutHub. Ngoại trừ một số hạn chế về đăng ký và thực thi event trong template:

// LayoutHub Editor không hỗ trợ
<div @click="method">...</div>

Chúng tôi không hỗ trợ đăng ký events trong template để đảm bảo chuẩn đầu ra tương thích với Shopify và các dữ liệu cũ của người dùng vẫn có thể hoạt động được.

Tất cả kịch bản javascript để thực thi cho layout cần viết thông qua phương thức @javascript hoặc trong file /script.js.

Dưới đây chúng tôi đề xuất một số các cú pháp chuẩn được dùng phần lớn trong quá trình xây dựng layout:

section.lh (Điều kiện)
<template>
    <div v-if=" settings.layout == 'flat' " class="flat">
        ...
    </div>
    <div v-else-if=" settings.layout == 'column' " class="colum">
        ...
    </div>
</template>
section.lh (Vòng lặp)
<template>
    <div class="items">
        <div v-for="(item, index) in settings.items" :key="index">
            ...
        </div>
    </div>
</template>
section.lh (In dữ liệu ra)
<template>
    <div class="item">
        
        // 1. In dữ liệu escaped mã HTML
        <span v-text="settings.name"></span>
        
        // 2. In dữ liệu HTML nguyên bản
        <span v-html="settings.name"></span>
        
        // 3. In dữ liệu hỗ trợ đa ngôn ngữ 
        <span v-text="lang(settings.name)"></span>
        <span v-html="lang(settings.name)"></span>
        
    </div>
</template>
section.lh (Attribute động)
<template>
    <div class="item">
        
        // Chỉ có 1 attribute động
        <img :src="settings.img" />
        
        // Nhiều attributes động phải dùng v-bind
        
        // Ưu tiên dùng computed khi không có payload
        <img v-bind="img_attributes_computed" />
        
        // Chỉ dùng methods đối với trường hợp cần truyền payload
        <div v-for="(img, i) in settings.images" :key="i">
            <img v-bind="img_attributes_method(img)" />
        </div>
        
    </div>
</template>

<script>
export default {
    computed: {
        img_attributes_computed() {
            return {
                src: this.settings.img.src,
                alt: this.settings.img.alt ? this.settings.img.alt : 'Untiled',
                class: 'featured-image '+this.settings.img.classes
            }
        }
    },
    methods: {
        img_attributes_method( payload ) {
            return {
                src: payload.src,
                alt: payload.alt ? payload.alt : 'Untiled',
                class: 'featured-image '+payload.classes
            }
        }
    }
}
</script>
section.lh (Sử dụng liquid)
<template>
    // In kết quả dạng html của code liquid đã được server xử lý
    <div v-html="liquid('product-title')"></div>
    
    // Sử dụng component Liquid để gọi code liquid (Đối với những code liquid không cần in gì ra)
    <Liquid name="product-form" />
</template>
Gọi component và truyền giá trị tương tự Vuejs
<template>
    <div class="my-section">
        ...
        <MyCom static_prop="Hello" :dynamic_prop="your_data" />
        ...
    </div>
</template>
Tên component là tên các file *.lh bên trong thư mục /components/
<template>
    <div class="my-component">
        {{prop_one}}
    </div>
</template>

<script>
export default {
    props: ['static_prop', 'dynamic_prop']
}
</script>
Đăng ký javascript cho section và components
<template>
    <div class="my-section">
        <a href="#">Click on me</a>
    </div>
</template>

// Đây là kịch bản javascript được dùng để chạy khi export ra môi trường thực
// Khuyến khích viết các mã javascript cho layout ở file /script.js 
// Hoặc viết trong cặp thẻ @javascipt ... @endjavascript của các component

@javascript
    // Biến this đại diện cho root element <div class="my-section">
    $(this).find('a').on('click', () => { ... });
@endjavascript
Vuejs 3.x
Vuejs 3.x