[Function] Custom data

Status
Not open for further replies.

admin

Administrator
Staff member
1. save_data
  • used to save data to the database
  • syntax:
    Code:
    save_data(key, data)
    in which:
  • key (string): repository name
  • data (array): array of data that needs to be stored. usually json.
    example:
    Code:
    {% do save_data('blog', {
        'title' => 'Hello world!',
        'content' => 'We are wap4 community'
    }) %}




2. get_data_count
  • used to count the number of entries stored in a repo
  • syntax:
    Code:
    get_data_count(key)




3. get_data
  • used to get the data list of a repo
  • syntax:
    Code:
    get_data(key, per_page, page, order, sort)
    in which:
  • key (string): repository name
  • per_page (int): number of entries on a page
  • page (int): current page
  • order (string): filter by list. usually id or time.
  • sort (string): usually asc or desc.




4. get_data_by_id
  • used to get data according to id field of that data
  • syntax:
    Code:
    get_data(key, id)
  • result: array
    Code:
    [
        'id' => 1,
        'data' => [
            'title' => 'Hello world!',
            'content' => 'We are wap4 community'
        ],
        'time' => 123456
    ]




5. check_data
used to check repo entries by id field. If the item exists, it returns true, otherwise false.
  • syntax:
    Code:
    check_data(key, id)




6. update_data_by_id
  • used to update data for entries
  • syntax:
    Code:
    update_data_by_id(key, id, data)
    in which:
  • key (string): repository name
  • id (int): id of entry
  • data (array): array of data that needs to be stored. usually json.




7. delete_data_by_id
  • syntax:
    Code:
    delete_data_by_id(key, id)




8. delete_data_by_key
  • syntax:
    Code:
    delete_data_by_key(key)
 
Last edited:
Update the "get_data_count" function:
Assume an entry named "blog" with data in JSON format:
JSON:
{"category":1,"name":"first article","slug":"first-article"}

If you want to count the total entries that contain category=1, use:
Code:
{{ get_data_count('blog', {'category':1}) }}

General syntax:
Code:
get_data_count(key, filter)
- If the filter parameter is empty, this function will return the total number of entries with the name "key"
 
Status
Not open for further replies.
Back
Top