Smarty Plugin
You can use Smarty plugins for custom processing or batch processing.
This documents provides the list of available Smarty plugins in Kuroco.
add
Add a number to a variable.
Attributes
Param | Type | Description |
---|---|---|
var | String | The variable name to which the addition is performed. The result of the addition is also stored in the same variable name. (required) |
value | Int | Number |
Example
{add var=i value=5}
api
Call an external API.
Sends a request to an external service that provides an API and stores the response in a variable.
Attributes
Item | Usage | Example | Note |
---|---|---|---|
endpoint | Endpoint (required) | https://example.com/brah/ | |
method | Method | POST /GET /PATCH /PURGE /PUT /DELETE | |
query | Query string | param1=hoge¶m2=foo | |
queries | Query array | $params | |
json_body | Request JSON body | {param1:"hoge",param2:"foo"} | |
body | Request body | ||
files | File | ['path/to/hoge.jpg', 'path/to/foo.png'] /[{'path':'path/to/hoge.jpg'}, {'path':'path/to/foo.png'}] | Specify the relative path from the Kuroco temporary folder. |
headers | Request headers | ['Host: localhost','user-agent: hoge'] | Specify as an array. |
cache_time | Cache time (minutes) | 20 | |
var | Storage variable of the response | response | |
json_var | Storage variable of the response | response | If the response is in JSON format, the decoded value is stored. |
resp_header_var | Response header storage variable | header | The response headers will be stored in an array format. |
dl_flg | Download flag | true /false | If true , the response is saved as a file in the Kuroco temporary area. |
status_var | 0: Failure 1: Success | status | Returns whether the request was successful or not. |
timeout | Timeout | 60 | Specify the timeout (in seconds). |
sslcert | secret key of mTLS client certificate | SSLCERT001 | Specify a Kuroco secret key of mTLS client certificate |
sslkey | secret key of mTLS client secret key | SSLKEY001 | Specify a Kuroco secret key of mTLS client secret key |
cainfo | secret key of mTLS Server CA info | CAINFO001 | Specify Kuroco secret key of mTLS Server CA info |
Example
Sending a file with PUT
To send a file to a specific URL with the PUT method, specify an array of file paths in the files
attribute. However, only one file can be sent at a time. Therefore, all elements after the second element in the specified array will be ignored.
{write_file var=tmp_path value="This is test."}
{assign_array var=files values=""}
{append var=files value=$tmp_path}
{api
endpoint='https://www.example.com/brah/'
method="PUT"
var=response
files=$files
status_var=status
}
Sending text with PUT
To send text with PUT, set the text you want to send to the json_body
attribute or the body attribute. If it is in JSON format, set the value to the json_body
attribute.
{assign_array var=product values=""}
{append var=product index=name value='apple'}
{append var=product index=price value='160'}
{assign var=json value=$product|@json_encode}
{api
endpoint='https://www.example.com/brah/'
method='PUT'
json_body=$json
var=response
status_var=status
}
If the text is not in JSON format, set the value to the body
attribute.
In this case, you must specify something in the Content-Type of the request header in the format text/***
. Also, note that even if the text is not in JSON format, you still need to add the json_encode
modifier, similar to the settings when using json_body
(this is because the multi-byte character part needs to be escaped to Unicode).
{assign_array var=headers values=""}
{append var=headers value='Content-Type: text/csv'}
{assign var=csv value="ID,NAME,PRICE\n1,apple,150\n2,orange,200"}
{api
endpoint='https://www.example.com/brah/'
method='PUT'
headers=$headers
body=$csv|@json_encode
var=response
status_var=status
}
Communicate by performing server-to-server authentication using mTLS authentication
If mTLS authentication is required to link with an external system, you can communicate with Kuroco as an mTLS client.
First, save the contents of the server CA certificate, client certificate, and client private key as secrets. You must specify the secret key name when saving. Please specify this secret key name as follows.
{api
endpoint='https://xxx.xxx.xxx/xxxx/'
method='GET'
var='response'
status_var='status'
sslcert='SSLCERT001'
sslkey='SSLKEY001'
cainfo='CAINFO001'
}
The client CA certificate used when creating the client certificate and client private key must be registered as a connection source certificate that is allowed on the mTLS server side. The registration method differs depending on the system, so please contact the provider of each service. Please receive the server CA certificate set here from the destination server. The connection results are output to the API log, so please refer to it when making settings.
Related Document
For information on how to call Kuroco's internal API using custom function, refer to Can I call Kuroco's API using custom function?.
api_internal
Requests an API internally and assign the response.
Attributes
Param | Type | Description |
---|---|---|
endpoint | String | Endpoint (required) |
method | String | Method (POST/GET) |
query | String | Query string |
queries | Array | Query array |
headers | Array | Request headers |
cache_time | Integer | Cache time (minutes) |
var | String | Variable name to store the response |
status_var | String | 0:Failed 1:Success |
member_id | Integer | Execute as the specified login member *Note: Cannot be used in conjunction with the 'direct' parameter. |
use_current_session | Boolean | Execute API request by taking over the current session |
direct | Boolean | Execute API request directly without going through the network (curl) *Note: You can specify direct=true as a parameter only if the HTTP method of the target endpoint is GET. It cannot be used in conjunction with 'member_id'. |
Example
{api_internal
endpoint='/rcms_api/1/sample'
method='GET'
query='ex=1&ex2=2'
cache_time=20
var='response'
status_var='status'}
api_method
Operations on each model are performed without creating an endpoint. Only operations with the GET method are available. Operations with the POST method cannot be used.
Attributes
Param | Type | Description |
---|---|---|
var | String | The variable name to store the result (required) |
model | String | Model |
method | String | Method (operation) |
version | Integer | Version |
request_params | Array | Request variables |
method_params | Array | Method settings. Same as "Basic Settings" and "Advanced Settings" on the endpoint settings page. |
Example
{* Endpoint configuration parameters *}
{assign_array var='method_params' values=''}
{assign_array var='method_params.topics_group_id' values='1'}
{* Query parameters *}
{assign_array var='request_params' values=''}
{assign var='request_params.cnt' value=20}
{assign var='request_params.pageID' value=1}
{api_method
var='topics_list'
model='Topics'
method='list'
version='1'
method_params=$method_params
request_params=$request_params}
test:{$topics_list|@debug_print_var}
api_mng
Requests a management API internally and assigns the response.
Attributes
Param | Type | Description |
---|---|---|
endpoint | String | Endpoint (required) |
method | String | HTTP Method (POST/GET) |
query | String | Query string |
queries | Array | Query array |
headers | Array | Request headers |
files | Array | Uploaded files |
var | String | Variable to store the response |
status_var | String | 0: Failure 1: Success |
member_id | Integer | Execute as the specified login member |
use_current_session | Boolean | Execute API request by inheriting the current session |
Example
{api_mng
endpoint='/management/<module>/sample'
method='GET'
query='ex=1&ex2=2'
var='response'
status_var='status'}
append
Append a new element to an array from a template.
Attributes
Param | Type | Description |
---|---|---|
var | String | The name of the array (required) |
value | String | The name of the object or array to add (required) |
index | Integer | The index of the array where to start adding (optional) |
Example
{append var=options value='Option N' index='N'}
assign_api_credential
Generate a new API request and get the access key in val
.
Attributes
Param | Type | Description |
---|---|---|
dg_key | String | The key to generate DG_CODE |
dg_id | String | The id to generate DG_CODE |
api_key | String | The key to generate sid request (required) |
var | Array | The name of the returning array |
jwt_data | Array | JWT data |
member_id | Integer | Member ID |
expire | Integer | Expiration time (in seconds) |
Example
{assign_api_credential
api_key=$api_key
dg_key="topics_edit_api"
dg_id="0"
var=val}
assign_array
Assign an array as a template variable.
Attributes
Param | Type | Description |
---|---|---|
var | String | The name of the variable to assign the array to (required) |
values | String | The values to store in the array. A string separated by a delimiter |
delimiter | String | The delimiter to use to split the values specified in 'values'. The default is a comma |
keys | String | If it's an associative array, specify the keys. The default is null |
Example
{assign_array var="foo" values="bar1,bar2"}
{assign_array var="foo" values="bar1;bar2;bar3" delimiter=";"}
{assign_array var="foo" keys="key1,key2,key3" values="bar1,bar2,bar3"}
assign_array_diff
Assigns the difference array between array1 and array2.
Attributes
Param | Type | Description |
---|---|---|
var | String | Name of the assigned diff array |
array1 | Array | Array 1 |
array2 | Array | Array 2 |
diff_mode | String | Mode of the diff array: normal, key |
Example
{assign_array_diff
var="foo"
array1=$array1
array2=$array2
diff_mode='normal'}
assign_array_intersect
Assigns the intersection array between array1 and array2.
Attributes
Param | Type | Description |
---|---|---|
var | String | Name of the assigned intersect array |
array1 | String | Array 1 |
array2 | String | Array 2 |
intersect_mode | String | Mode of the intersect array: normal, assoc, key (default=normal) |
Example
{assign_array_intersect
var="foo"
array1=$array1
array2=$array2
intersect_mode='normal'}
assign_array_set
Append an element to an array.
This function is similar to {append}, but this function appends element without changing the original array.
Attributes
Param | Type | Description |
---|---|---|
var | String | The name of the return variable (required) |
from | String | Original array |
key | String | key name |
value | String | value |
Example
{assign_array var="person" values=""}
{append var="person" index="name" value="Katoh"}
{append var="person" index="job" value="Sales"}
{assign_array_set var="person_ex" key="age" value="28" from=$person}
{$person_ex|@debug_print_var}
{$person|@debug_print_var}
Output
Array (4)
name => "Katoh"
job => "Sales"
age => "28"
Array (2)
name => "Katoh"
job => "Sales"
assign_csv_table
Retrieve a master indicated by csvtable_id.
Attributes
Param | Type | Description |
---|---|---|
csvtable_id | Integer | The ID of the master (required) |
var | String | The name of the return variable (required) |
get_key_val | Boolean | Enable the use of optional parameters. (optional) |
key_idx | Integer/Array | Return dimension or dimensions to be returned. (optional) |
value_idx | Integer | Return dimension or dimensions to be returned. (optional) |
multiple | Boolean | Distinguish by the number of dimensions. (optional) |
lang | String | If it supports multiple languages, specify the language such as "ja", "en", etc. |
table_name | String | The name of the return variable (backward compatibility) |
Example
{assign_csv_table csvtable_id=X var="sample_table1"}
{$sample_table1|@debug_print_var}
{assign_csv_table
csvtable_id=X
var="sample_table2"
get_key_val=true}
{$sample_table2|@debug_print_var}
assign_favorite_cnt
Retrieve favorite count.
Attributes
Param | Type | Description |
---|---|---|
module_type | String | The module name. Specify one of "topics" ,"comment" ,"member" ,"tag" ,"csvtable" , or "ec_product" . The default is "topics" . |
module_id | Integer | The ID of the specified module. |
var | String | The name of the variable to store the result (required). |
time | String | The strtotime format. |
format | String | The format. |
Example
{assign_favorite_cnt
module_type="topics"
module_id=1000
var="favorite_cnt"}
assign_globals
Assigns global variables that can be shared between custom processes called within the same request.
Attributes
Param | Type | Description |
---|---|---|
var | String | Variable name to store global variables. |
key | String | Key for global variables. |
value | Mixed | Value of the global variable. |
unset | Bool | To clear the value of a variable, specify true. |
Example
{assign_globals key='prev_content' value=$content}
{assign_globals var='prev_content' key='prev_content'}
assign_group_nm
Retrieve group names.
Attributes
Param | Type | Description |
---|---|---|
group_id | Integer | Group ID (required) |
var | String | The name of the variable to store the result (required). |
lang | String | The language code (e.g., "ja", "en"). |
Example
{assign_group_nm group_id=100 var='group_nm'}
assign_my_favorite_cnt
This function retrieves the number of contents that the user has marked as their favorite.
Attributes
Param | Type | Description |
---|---|---|
module_type | String | The name of the module. Specify one of "topics" , "comment" , "member" , "tag" , "csvtable" , or "ec_product" . The default is "topics" . |
module_id | Integer | The ID of the specified module. |
var | String | The variable name to store the result (required). |
cookie_flg | Integer | The flag for getting favorite contents with cookie management. |
action_type | String | The target action (default 0 (like)). |
Example
{assign_my_favorite_cnt
module_type="topics"
var="favorite_cnt"
cookie_flg=1}
assign_member_detail
Retrieve member's information.
Attributes
Param | Type | Description |
---|---|---|
var | String | The name of the variable to store the result (Required) |
member_id | Int | The member ID of the value to retrieve (Required)| |
open_by_group | Boolean | When false, the viewing permission is ignored. The default value is true . |
open_flg | Int | (Deprecated) When -1, only information about members who can view is retrievable. |
assign_group_flg | Boolean | Whether to retrieve group information or not. |
Example
{assign_member_detail var='varname' member_id=7}
assign_new_comment_list
Retrieves the comments attached to the specified content, sorted from the newest to the oldest.
Attributes
Param | Type | Description |
---|---|---|
module_id | String | The ID of the module where the content is specified. |
module_type | String | The name of the module. Specify either "topics", "comment", "member", "tag", "csvtable", or "ec_product". Default is "topics". |
var | Boolean | The variable name to store the result (required). |
new_order_flg | String | When set to false , the results are returned in ascending order. |
cnt | String | Limits the number of results. Default is 5 . |
Example
{assign_new_comment_list
module_id=1
module_type='topics'
cnt=5
var='new_comment_list'
}
assign_relation_tag_list
Retrieve the list of tags associated with the specified content.
Attributes
Param | Type | Description |
---|---|---|
module | String | Module name |
module_id | Integer | ID in the specified module (required) |
var | String | Variable name to store the result (required) |
tag_category_id | Integer | If you want to narrow down by tag category, specify the tag category ID (optional) |
tag_relation_list | Array | Array of tags. It must be an array of arrays that have id (optional) |
Example
{assign_relation_tag_list
module="topics"
module_id=123
var="rel_tag_list"}
{assign_array var=tag1 values=""}
{append var=tag1 index=id value=101}
{append var=tag1 index=tag_nm value="WeaklyRecommended"}
{assign_array var=tag2 values=""}
{append var=tag2 index=id value=102}
{append var=tag2 index=tag_nm value="Important"}
{assign_array var=tag_list values=""}
{append var=tag_list value=$tag1}
{append var=tag_list value=$tag2}
{assign_relation_tag_list
module="topics"
module_id=123
tag_relation_list=$tag_list
var="rel_tag_list"}
assign_tag_category_list
Returns a list of category tags.
Attributes
Param | Type | Description |
---|---|---|
var | String | The name of the variable to store the result in (required) |
lang | String | Language code setting |
tree_flg | Boolean | Flag for outputting tag hierarchy structure (e.g. parent and child tags) (returns 1) |
Example
{assign_tag_category_list [tree_flg=true] var=tag_category_list}
assign_tag_list
Gets the tags associated with the tag category.
Attributes
Param | Type | Description |
---|---|---|
var | String | The name of the variable to store the result in (required) |
category_id | Integer | The ID of the category tag to specify (required) |
order | Array | An array that specifies the output order of tags. |
Example
{assign_tag_list category_id='02' var='tag_list'}
{assign_tag_list category_id='02' order='open_contents_cnt:desc' var='tag_list'}
{assign_tag_list category_id='02' order=$tag_order var='tag_list'}
assign_topics_category_list
Retrieve a list of contents associated with the specified category.
Attributes
Param | Type | Description |
---|---|---|
var | String | The variable name to store the result (required). |
topics_group_id | Integer | The topics_group_id of the category group to be specified (required). |
lang | String | Language setting. |
Example
{assign_topics_category_list
topics_group_id=1
var='topics_category_list'}
assign_topics_detail
Get detailed information of the specified content.
Attributes
Param | Type | Description |
---|---|---|
var | String | Variable name to store the result (required) |
topics_id | Integer | ID of the content (required) |
id | Integer | ID of the content (Specify either topics_id or id. If both are present, topics_id will be given priority.) |
lang | String | Language setting |
chk_open_flg | Boolean | Whether to limit the content to only those that are currently open. The default is true . |
Example
{assign_topics_detail topics_id=100 var='topics_data'}
backup
Performs a backup.
Attributes
Param | Type | Description |
---|---|---|
type | String | Specify "full" |
memo | String | Memo for the backup |
result_var | String | Variable name to store the result |
Example
{backup type='full' memo='smarty' result_var='res'}
backup_delete
Deletes a backup.
You must specify either a backup ID or a backup period (start date and end date). If a backup ID is specified, the backup period (start date and end date) will be ignored.
Attributes
Param | Type | Description |
---|---|---|
backup_id | String | Specify the backup ID |
start_date | String | Specify the start date of the backup period to delete |
end_date | String | Specify the end date of the backup period to delete |
result_var | String | Variable name to store the result. If the deletion is successful, it returns true; if it fails, it returns false. |
Example
{backup_delete backup_id='1234' result_var='res'}
{backup_delete start_date='2020-01-01 00:00:00' end_date='2020-01-01 23:59:59' result_var='res'}
site_sync
Synchronize between sites. A 6-hour interval is required since the last time this plugin was performed.
Attributes
Param | Type | Description |
---|---|---|
from_site_key | String | Site key of synchronization source |
to_site_key | String | Site key of synchronization destination If no specific designation is provided, it will synchronize with your own website. |
sync_type | Integer | 1:Sync App design 2:Full sync |
Example
{site_sync from_site_key='from_example_key' to_site_key='to_example_key' sync_type='1'}
break
Used inside loops such as foreach or section. When break is executed, the program immediately exits the loop.
Attributes
none
Example
{break}
batch
Attributes
Param | Type | Description |
---|---|---|
batch_id | Integer | Batch ID (Either this value or name is required) |
name | String | Slug of batch (Either this value or batch_id is required) |
module | String | Target module name (It used when you register default batch) |
ext_data | Array | Data to pass to the registered batch. |
var | String | Variable name which stores registered batch id |
Example
{batch batch_id='1234' ext_data=$ext_data}
child_site
Get data of a child site.
Attributes
Param | Type | Description |
---|---|---|
site_key | String | Site key (required) |
var | String | Name of the variable to store the result (required) |
Example
{child_site var='site' site_key='1234'}
continue
This is used within loops such as foreach and section. When continue is executed, the remaining processing of the loop is skipped and the program moves on to the next loop processing.
Attributes
None
Example
{continue}
cookie
Get/set Cookie.
Attributes
Param | Type | Description |
---|---|---|
var | String | Variable name |
key | String | Key |
value | String | String value |
expires | Integer | Expiration date of the cookie in days |
overwrite | Integer | Overwrite flag |
Example
{cookie key="foo" value="test"}
date
Assigns a date variable.
Attributes
Param | Type | Description |
---|---|---|
var | String | Variable name to store the result (required) |
time | String | strtotime format |
format | String | Format |
Example
{date var='yesterday' time='Yesterday' format='Y-m-d'}
{date var='today' format='Y-m-d H:i:s'}
function
Calls a custom function.
Attributes
Param | Type | Description |
---|---|---|
var | String | Variable name to store the result (required) |
id | Integer | ID of the custom function |
name | String | Identifier of the custom function |
Example
If you have defined a custom function "sub_function" as follows and called it using the function
plugin, the variable $result
will be assigned with the value "Hello World".
{* Caller *}
{function name="sub_function" var="result" param1="Hello" param2="World"}
{* Custom function definition. Identifier: sub_function *}
{assign var="message" value=$param1|cat:" "|cat:$param2}
{return value=$message}
gcloud_functions_token
Obtain a bearer token for authentication with Google Cloud Functions.
Attributes
Param | Type | Description |
---|---|---|
var | String | Variable name to store the result (required) |
url | String | URL of the function (required) |
sa_secret_name | String | Name of the secret for the service account set in the secret_edit screen. |
Example
{gcloud_functions_token
var="id_token"
url="https://us-central1-**.cloudfunctions.net/functionName"
sa_secret_key='GCP_MY_CREDENTIAL'}
gcloud_pubsub_publish
Delivers a message to Google Cloud Pub/Sub.
Attributes
Param | Type | Description |
---|---|---|
var | String | Variable name to store the result (required) |
topic | String | Topic name to deliver the message to (required) |
message | Any | Message to be delivered (required) |
project | String | GCP project name |
sa_secret_name | String | Secret name of the service account set in the secret_edit page |
Example
{gcloud_pubsub_publish
var='result'
project='projectName'
topic='topicName'
message=$message
sa_secret_name='MY_GCP_CREDENTIAL'}
get_file
Gets a file from S3, GCS, external URL, etc.
Attributes
Param | Type | Description |
---|---|---|
var | String | Variable name to store the result |
path | String | Path to the file on S3/GCS to retrieve |
url | String | URL of the file to retrieve |
bucket | String | Bucket name on S3/GCS where the file to retrieve is located |
save | Boolean | Whether to save the retrieved file in Kuroco's temporary area. If set to false, the content of the file is saved to the variable specified by var without saving it. |
save_path | String | File name to save the retrieved file |
Example
{get_file path=$path}
generate_pdf
Generate a PDF or image based on the specified URL. The generated file will be saved on GCS.
Note that generate_pdf
uses the headless browser Puppeteer. The width and height of the headless browser can be controlled by various options.
Prerequisites
To use generate_pdf
, you need to integrate it with Firebase. Refer to Cloud storage integration with Firebase for integration.
Attributes
Item | Description | Example |
---|---|---|
url | Specify the URL of the page to convert to PDF. | https://www.diverta.co.jp |
path | Specify the file storage location for the generated PDF. It will be located under files/g/private/ or files/g/public/ . | files/g/private/sample.pdf |
option | Specify the options for PDF conversion. | |
browser_width | Specify the browser width. | browser_width=1280 |
browser_height | Specify the browser height. | browser_height=2560 |
sleep | Specify the waiting time (in milliseconds) until the specified page is captured. | sleep=1000 |
ua | Specify the user agent. This option is useful when the page specified by url switches its display depending on the user agent of the accessing browser. Note: If the correct string is not sent, it may not switch as intended. Please confirm the specifications of the target website before using it. | ua="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36" |
format | Specify the format of the file to be saved. pdf , png , jpeg , jpg , and webp are available. | format="png" |
cookie | Specify the URL that requires login to convert to PDF. Assumes the format of $smarty.cookies . Note: When using this plugin in batch processing, $smarty.cookies will be empty and cannot be used. Please use it in custom function as a pre-process or post-process of an API endpoint. | cookie=$smarty.cookies |
domain | Specify the domain of the cookie. | domain="www.diverta.co.jp" |
overwrite | Specify whether to overwrite the file if it already exists. | overwrite=1 |
callback_batch | Specify the slug name of the batch processing if you want to execute Kuroco's batch processing after the PDF is generated. | callback_batch="my_callback_batch" |
data | You can specify other parameters. This parameter is passed to the above batch processing. | data=$smarty.request.data |
Example
{generate_pdf
url="https://www.diverta.co.jp"
path="files/g/private/sample.pdf"
cookie=$smarty.cookies
domain="www.diverta.co.jp"
}
Related document
Refer to Scheduled generation of screenshot PDFs of external sites for the detail of how to use generate_pdf
.
github_deploy
Build and deploy front-end through integration with GitHub.
Attributes
Param | Type | Description |
---|---|---|
result_var | String | true: success false: failure |
Example
{github_deploy result_var='res'}
googleanalytics
Get data from Google Analytics and set values in the counter table.
When passing the content ID to the sync_counter batch processing with the Smarty plugin of batch, you can apply the set values to the content.
Attributes
Param | Type | Description |
---|---|---|
var | String | Variable name to assign data retrieved from Google Analytics |
updated_topics_ids | Array | An array of content IDs where counter values have been set |
update_column_slug | String | Slug of the column to update. |
update_column_index | Integer | Index of the column to update. |
update_target_metric | String | Metric to use for update. |
update_target_dimension | String | Custom dimension to update. |
topics_group_id | Integer | Content definition ID. |
startDate | String | Start date of the aggregation period. Can be interpreted by PHP's strtotime().Default value is a 7 days before. |
endDate | String | End date of the aggregation period. Can be interpreted by PHP's strtotime().Default value is today. |
queries | String | Directly specify the query. |
Example
{googleanalytics
var="result"
update_column_slug="pv"
update_target_dimension="customEvent:slug"
updated_topics_ids='updated_topics_ids'
topics_group_id=1}
{assign_array var=ext_data values=''}
{assign var=ext_data.topics_ids value=$updated_topics_ids}
{batch module='topics' name='sync_counter' ext_data=$ext_data}
logger
Logs to info.log. You can check it by going to [Operations]->[Log Management]->[Custom Log].
Attributes
Param | Type | Description |
---|---|---|
msg1 | String | String 1(within 1KB) |
msg2 | String | String 2(within 1KB) |
msg3 | String | String 3(within 1KB) |
msg4 | String | String 4(within 1KB) |
Example
{logger msg1=$log1 msg2=$log2}
login
Log in.
Attributes
Param | Type | Description |
---|---|---|
member_id | Integer | Member ID |
overwrite | Boolean | Whether to overwrite the current session if already logged in (i.e. login again). |
Example
{login member_id=2 overwrite=false}
logout
Log out.
Attributes
None.
Example
{logout}
lottery
Lottery function.
Attributes
Param | Type | Description |
---|---|---|
var | String | The variable name to store the result (required) |
cnt | Integer | The number of IDs to be drawn |
duplicate | Integer | The number of duplicates |
ids | Array | Target IDs (required) |
exclude_ids | Array | Excluded IDs |
Example
{lottery
var='foo'
cnt=3
duplicate=0
ids=$ids
exclude_ids=$exclude_ids}
pg_dateformat
Format the date and time based on the format. Please specify the format embedded by DateTimeInterface::format(). The three-letter notations for days of the week and months are converted to their respective language representations by the latest locale.
Attributes
Position | Type | Description |
---|---|---|
1 | String | format |
Example
{"2024-06-01 12:34:56"|pg_dateformat}
{"2024-06-01 12:34:56"|pg_dateformat:"Y-m-d(D) [H:i:s]"}
{"2024-05-01 12:34:56"|pg_dateformat:'M'}
{"-2 days"|pg_dateformat}
{"-1 hour"|pg_dateformat}
Output
2024/06/01(Sat) 12:34
2024-06-01(Sat) [12:34:56]
May
2024/06/19(Wed) 15:45
2024/06/21(Fri) 14:45
pg_dateformat2
Format the date and time based on the format.
Please specify the format embedded by DateTimeInterface::format().
The three-letter notations for days of the week and months are converted to their respective language representations by the latest locale.
Also, if the target date and time is within 24 hours, it will be converted to H:i:s(Updated s seconds ago)
in HTML format. If this conversion is not necessary, please use pg_dateformat.
Attributes
Position | Type | Description |
---|---|---|
1 | String | format |
Example
{"2024-06-01 12:34:56"|pg_dateformat2}
{"2024-06-01 12:34:56"|pg_dateformat2:"Y-m-d(D) [H:i:s]"}
{"2023-05-01 12:34:56"|pg_dateformat2:'M'}
{"-2 days"|pg_dateformat2}
{"-1 hour"|pg_dateformat2}
Output
2024/06/01(Sat) 12:34
2024-06-01(Sat) [12:34:56]
May
2024/06/19(Wed) 15:45
<span style="color:#5FAF23;font-weight:bold;">14:45:51(Updated 1 hours ago)</span>
purge_cdn_cache
Purge (delete) the CDN cache.
Attributes
Param | Type | Description |
---|---|---|
api_endpoint | String | Specify the URL of the endpoint. |
module | String | Specify the module name. Currently, it supports topics and csvtable and all (required). |
topics_group_id | int | If the module name is specified as topics , specify the content definition ID. |
csvtable_id | int | If the module name is specified as csvtable , specify the ID of the master. |
Example
{purge_cdn_cache api_endpoint='/rcms-api/1/list'}
{purge_cdn_cache module='all'}
{purge_cdn_cache module='topics' topics_group_id=123}
{purge_cdn_cache module='csvtable' csvtable_id=123}
put_file
Uploads a file to KurocoFiles or S3/GCS storage.
Attributes
Param | Type | Description |
---|---|---|
tmp_path | String | The path of the file to upload. Specify a file in the temporary folder. |
path | String | The destination path of the file. |
value | String | The content to write to the file. |
files_path | String | The path on KurocoFiles (/files/(user |
bucket | String | The name of the S3/GCS bucket to upload to. |
Example
{put_file tmp_path=$tmp_path path=$upload_path}
read_dir
Get a list of files that exist in KurocoFiles and repeat.
Attributes
Param | Type | Description |
---|---|---|
name | String | The name used to identify the read_dir block. |
file_var | Object | The Smarty variable name to store the following file information: - path: File path - size: File size (in bytes) - ctime: File content modification date (timestamp) - mtime: File attribute (e.g., file name) modification date (timestamp) - is_dir: Whether it's a directory or not. |
path | String | The path of the target directory to retrieve. Specify either /files/user or /files/ltd as subdirectories. |
pattern | String | If you want to filter by file path, specify a regular expression here. |
recursive | Boolean | When set to true, it will recursively retrieve the contents of subdirectories. |
name_only | Boolean | When set to true, the file_var variable will return only the file path as a string. |
type | String | Specify 'file' or 'dir' to iterate over files only, directories only, or both if not specified. |
Example
{read_dir name="hoge" file_var='file' path='/files/user'}
{$file|@debug_print_var}
{/read_dir}
read_file
Reads a file line by line and iterates through it.
Attributes
Param | Type | Description |
---|---|---|
name | String | Name to identify the read_file block. |
path | String | pecify the file path as a relative path from /files/. The accessible directories are as follows:
|
row | String | Smarty variable to store one line of read data. |
type | String | File format. Specify 'txt', 'csv', or 'jsonl'. If not specified, the default is 'txt'. |
ignore_permissionRelease version: βversion | Boolean | If the /files/topics/ or /files/member/ directory is specified and true is set, the file will ignore the publication status and permission settings of the saved content. |
Example
{read_file name="hoge" path='foo.txt' row="row"}
{$row|escape}
{/read_file}
rcms_match
Calls the preg_match
function.
Attributes
Param | Type | Description |
---|---|---|
var | String | The variable name to store the result (required) |
pattern | String | The pattern to search for |
subject | String | The input string |
flags | Integer | You can specify the combination of the following flags. 256 - PREG_OFFSET_CAPTURE: If this flag is set, the offset of each match in bytes will also be returned. Be careful to change the value of var to an array. All elements of the array consist of the string matched at offset 0 and the offset to the subject at offset 1 of the string. 512 - PREG_UNMATCHED_AS_NULL: When this flag is passed, the unmatched subpattern is reported as null. If not passed, it is reported as an empty string. |
offset | Integer | The starting position of the search. Default is from the beginning. |
Example
{rcms_match
var='foo'
pattern='/^ex+/'
subject='example'
flags=256}
{rcms_match
var='foo'
pattern='/^ex+/'
subject='example'
flags=512
offset=2}
rcms_match_all
Calls the preg_match_all
function.
Attributes
Param | Type | Description |
---|---|---|
var | Array | The variable name to store the result (required). |
pattern | String | The string representing the pattern to search for. |
subject | String | The input string. |
flags | Integer | You can specify a combination of the following flags:1 - PREG_PATTERN_ORDER: If you specify the variable name as $matches , $matches[0] is an array of strings that matched the entire pattern, $matches[1] is an array of strings that matched the first subpattern, and so on.2 - PREG_SET_ORDER: $matches[0] is an array of values captured by the first match, $matches[1] is an array of values captured by the second match, and so on.256 - PREG_OFFSET_CAPTURE: If you set this flag, the offset of each match will also be returned (in bytes). Note that you should change the value of var to an array. All elements of that array will consist of the string matched at offset 0 and the offset into subject at offset 1.512 - PREG_UNMATCHED_AS_NULL: If this flag is passed, any subpatterns that did not match will be reported as null. If this flag is not passed, they will be reported as an empty string. |
offset | Integer | The start position of the search. The default is the beginning. |
Example
{rcms_match_all
var='matches'
pattern='|<[^>]+>(.*)</[^>]+>|U'
subject='<b>example: </b><div align=\"left\">this is a test</div>'
flags=2}
{$matches|@debug_print_var}
Output
Array (2)
0 => Array (2)
0 => "<b>example: </b>"
1 => "example:"
1 => Array (2)
0 => "<div align=\"left\">this is a test</div>"
1 => "this is a test"
rcms_sort_by_key
Sorts an associative array by the value of a specified key.
Example
{assign var="product_list" value=$product_list|@rcms_sort_by_key:'price':'asc'}
rcms_strip_tags
Removes HTML and PHP tags from a string.
Example
{assign var="output" value=$input|rcms_strip_tags:'<br>'}
rcms_hash
Calls the hash function.
Attributes
Param | Type | Description |
---|---|---|
var | String | Name of the variable to store the result (required) |
algo | String | Algorithm (default=sha256) |
data | String | Target string (required) |
key | String | Secret key for HMAC method |
binary | Boolean | When set to true, the result is stored in binary form. |
Example
{rcms_hash var='foo' data='hoge' key='salt'}
refresh_cs
Resets the custom member filter (MemberCustomSearch).
Attributes
Param | Type | Description |
---|---|---|
add | Array | Array of MemberCustomSearch IDs to be added. |
Example
{refresh_cs}
{assign_array var="custom_search_ids" values="1,2,3"}
{refresh_cs add=$custom_search_ids}
remove_dir
Removes a directory.
Attributes
Param | Type | Description |
---|---|---|
path | String | Path of the directory to remove. |
status_var | String | Name of the Smarty variable that will hold the result of the removal. |
Example
{remove_dir path='/files/user/hoge' status_var='status'}
remove_file
Removes files.
Attributes
Param | Type | Description |
---|---|---|
path | String | The path of the file to be deleted |
bucket | String | The name of the S3/GCS bucket where the file is located |
status_var | String | The name of the Smarty variable to store the deletion result |
Example
{remove_file path='/files/user/hoge.jpg' status_var='status'}
rename_file
Moves file.
Attributes
Param | Type | Description |
---|---|---|
src_path | String | Source path |
dest_path | String | Destination path |
Example
{rename_file src_path=$src_path dest_path=$dest_path}
return
Exits the custom function with an optional value.
Attributes
Param | Type | Description |
---|---|---|
value | Mixed | A value to return to the calling custom function. |
Example
To return a value from a custom function called "sub_function":
{return value="Hello"}
To call sub_function
in the different custom function:
{function name="sub_function" var="result"}
The value "Hello"
is stored in $result
variable.
save_file
Save as file.
Attributes
Param | Type | Description |
---|---|---|
value | String | Content to be saved. |
var | String | Variable name to store the result. |
Example
{save_file var='path' value=$value}
secret
Retrieves a secret.
Attributes
Param | Type | Description |
---|---|---|
var | String | The variable name to store the result (required) |
key | String | The name of the secret key (required) |
Example
{secret var='foo' key='hoge'}
sendmail
Sends an email.
Additionally, the variables provided as arguments to sendmail can be used within the message template.
Attributes
Param | Type | Description |
---|---|---|
var | String | The variable name to store the result. If successful, true will be stored; otherwise, false. |
to | String | The destination email address. |
subject | String | The email subject. |
contents | String | The email body. |
from | String | The FROM address. |
from_nm | String | The sender name of the FROM address. |
mail_template | String | The identifier of the message template. |
Variable Name | String | Specifies the variables to pass to the message template. |
Example1
{sendmail
var='result'
to=$mail_to
subject='testmail'
contents="This is test."
from="test@example.com"
from_nm="test"}
Example2
By doing the following, you can use the variable $member_detail in the message template.
{sendmail
var=result
to=$mail_to
subject='testmail'
mail_template='update_test'
member_detail=$member_detail
from="noreply@kuroco-mail.app"
from_nm="test"}
set_memory
Increases the memory allocation.
Attributes
Param | Type | Description |
---|---|---|
var | String | The specified memory capacity. Must be either 256M , 512M , or 768M . |
Example
{set_memory memory_limit='256M'}
slack_get_message
Gets a message from Slack.
Attributes
Param | Type | Description |
---|---|---|
var | String | The variable name to store the result in. |
channel | String | The ID of the channel. |
ts | String | The timestamp value of the message. |
Example
{slack_get_message
var='message'
channel='XXXXXXXXX'
ts='1675411163.005300'}
slack_post_message
Sends a message to Slack.
Attributes
Param | Type | Description |
---|---|---|
var | String | The name of the variable to store the result. If successful, it will store true , otherwise false . |
channel | String | The ID of the channel to post the message to. |
users | Array | An array of user IDs to mention in the message. |
text | String | The text of the message. |
thread_ts | String | The timestamp of the parent message in the thread. |
Example
{slack_post_message
channel='XXXXXXXXX'
users=$users
text='test'}
slack_team_info
Get information about a Slack team.
Attributes
Param | Type | Description |
---|---|---|
var | Array | The variable name to store the result. If the process fails, false is stored. |
team | String | The search condition. |
Example
{slack_team_info var='team' team=$team}
sleep
Delays the execution. Delay time can be set from a minimum of 100ms to a maximum of 1000ms.
Attributes
Param | Type | Description |
---|---|---|
ms | Integer | Time to stop in milliseconds. Must be greater than or equal to 100 and less than or equal to 1000. If a value outside this range is specified, the time is set to either 100ms or 1000ms. |
Example
{sleep ms=300}
storage_url
Get a signed URL to read a file from S3/GCS.
Attributes
Param | Type | Description |
---|---|---|
var | String | Name of the variable to store the result. |
path | String | Path of the file on S3/GCS. |
expire | String | Expiration time of the URL. Default is '+167 hour' . |
Example
{storage_url path=$path var='url' expire="+1 hour" }
strip
Removes line breaks in the enclosed area and applies trim to each line.
Attributes
None.
Example
{* All of the following examples will be output on a single line *}
{strip}
{foreach from=$contents item=content name='loop1'}
{if $content.topics_group_id == 1}
{$content.subject}
{/if}
{if !$smarty.foreach.loop1.last}
,
{/if}
{/foreach}
{/strip}
strtodate
Get date from timestamp.
Attributes
Param | Type | Description |
---|---|---|
var | String | Variable name to store the result (required) |
timestamp | Int|String | Timestamp |
format | String | Format |
Example
{strtodate var='today' timestamp='today' format='Ymd'}
subtract
Subtracts a number from a variable.
Attributes
Param | Type | Description |
---|---|---|
var | String | The variable name to store the result (required) |
value | Int | The number to subtract from the variable. |
Example
{subtract var='i' value=5}
unzip
Unzips a zip file.
Attributes
Param | Type | Description |
---|---|---|
src | String | The path to the zip file to be extracted. Must be a URL starting with https:// or a path on a cloud storage. |
dest | String | The path to the folder to store the extracted files. Must be a KurocoFiles path (/files/user/ , /files/temp/ , or /files/ltd/ ) or a GCS/S3 path (/files/g/ or /files/a/ ). |
bucket | String | The name of the bucket. If omitted, the storage specified in [External System Integration] - [Firebase] is used. |
callback_batch | String | The name of the batch processing to be called back after the zip extraction is complete. |
data | Mixed | Any data. Passed to the callback batch. |
overwrite | Integer | Whether to overwrite the file with the same name in the destination folder if it already exists. 0 or 1. |
detect_order | Array | You can specify the priority order when determining the character encoding of the file name of the deployed file. By default, it is set to ["utf8", "cp932", "EUC-JP"] . |
Example
{unzip
src='/files/g/private/temp/zip/hoge.zip'
dest='/files/g/private/temp/unzip/'
overwrite=1
callback_batch='batch1'
}
uuid
Retrieves uuid.
Attributes
Param | Type | Description |
---|---|---|
var | String | Variable to store. |
Example
{uuid var='foo'}
rcms_arsort
Sorts an array in descending order while maintaining the relationship between associative keys and elements.
Note: This is a modifier for an array, so the "@" symbol must be used as a prefix.
Attributes
None.
Example
{assign var="result_arr" value=$input_arr|@rcms_arsort}
rcms_asort
Sorts an array in ascending order while maintaining the relationship between the associative key and its corresponding value.
Note: This is a modifier for arrays, so it needs to be preceded by the "@" symbol.
Attributes
None.
Example
{assign var="result_arr" value=$input_arr|@rcms_asort}
rcms_file_size
Returns the size of the specified file.
Attributes
Position | Type | Description |
---|---|---|
1 | Integer | The format type of the result (default=1). |
2 | Integer | The precision of the result in decimals (default=2). |
Example
{$row.path|rcms_file_size}
rcms_in_array
A plugin that eliminates the need to write is_array
in Smarty when using in_array
.
Attributes
Position | Type | Description |
---|---|---|
1 | Array | list |
Example
{assign_array var=fruits values="apple,banana,orange"}
{if 'beef'|rcms_in_array:$fruits}
{assign var=message value='beef is fruits.'}
{else}
{assign var=message value='beef is not fruits.'}
{/if}
rcms_krsort
Sorts the array in reverse order by key.
Note: This is a modifier for arrays, so it must be prefixed with '@'.
Attributes
None.
Example
{assign var="result_arr" value=$input_arr|@rcms_krsort}
rcms_ksort
Sorts the array in order by key.
Note: This is a modifier for arrays, so it must be prefixed with '@'.
Attributes
None.
Example
{assign var="result_arr" value=$input_arr|@rcms_ksort}
rcms_rsort
Sorts an array in descending order.
Note: This is a modifier for an array, so you need to prefix it with "@".
Attributes
None.
Example
{assign var="result_arr" value=$input_arr|@rcms_rsort}
rcms_sort
Sorts an array in ascending order.
Note: This is a modifier for an array, so you need to prefix it with "@".
Attributes
None.
Example
{assign var="result_arr" value=$input_arr|@rcms_sort}
regex_replace
A regular expression search and replace on a variable.
Attributes
Position | Type | Description |
---|---|---|
1 | String | This is the regular expression to be replaced. |
2 | String | This is the string of text to replace with. |
Example
{assign var="string" value="This is KUROCO."}
{$string|regex_replace:"/kuroco/i":"Kuroco"}
{assign var="string" value="12,31,2023"}
{$string|regex_replace:'/(\d+),(\d+),(\d+)/':'$3-$1-$2'}
{assign var="string" value="本日は晴天なり"}
{$string|regex_replace:"/晴天/":"雨天"}
Output
This is Kuroco.
2023-12-31
本日は雨天なり
sort_name
Displays the last name and first name swapped when the language setting is set to English ('en'
).
Example
{'Yamada'|sort_name:'Taro'}
// If the language setting is set to 'en', 'Taro Yamada' will be displayed.
// Otherwise, 'Yamada Taro' will be displayed.
to_form_options
Converts an associative array to the format of [['key'=>$key, 'value'=>$value], ...]
.
Attributes
Position | Type | Description |
---|---|---|
target | Array | The array to be converted (required). |
Example
{assign var='form_options' value=$options_array|@to_form_options}
{assign var='form_options' value=$options_array|@to_form_options:'key':'label'}
to_object
Converts an array to a stdClass object.
Attributes
Position | Type | Description |
---|---|---|
target | Array | The array to be converted (required). |
Example
{assign var='foo' value=$bar|@to_object}
twitter_post_message
Sends a message to Twitter.
Attributes
Position | Type | Description |
---|---|---|
var | String | The variable name to store the result. |
text | String | The message to send. |
Related Documents
To use this plugin, you need to set up various items under [External System Integration] - [Twitter].
For detailed instructions on setting up integration with Twitter and automatically posting to Twitter when posting content, see Setting up Twitter integration.
update_counter
Updates the value of the counter type extended column of content.
Attributes
Param | Type | Description |
---|---|---|
var | String | The variable name to store the result. |
value | Integer | The value you want to set (Required) |
topics_group_id | Integer | Content definition ID (Required) |
slug | String | Target content's ID/Slug (Required) |
ext_slug | String | Target column's ID/Slug (Required) |
index | Integer | sequence number of the repeating column starting from 0 |
Example
{update_counter
var='result'
value=3
topics_group_id=10
slug='a-content'
ext_slug='a_col_slug'
index=0
}
write_file
Writes data to a file.
Attributes
Position | Type | Description |
---|---|---|
path | String | The file path. If omitted, the file is automatically written to a temporary area with a unique file name. |
var | String | The variable name to store the temporary file path that was written (required). |
value | String | Array | The data to be written. If an array is specified, it will be written in CSV format. |
is_append | Integer | Append mode. 0 or 1. If in append mode, path must be specified. |
Example
{write_file var="path" value="hoge"}
{write_file path=$path value="foo" is_append=1}
{write_file path=$path value="var" is_append=1}
xmltojson
Converts XML to JSON.
Attributes
Param | Type | Description |
---|---|---|
var | String | The variable name to store the result. (required) |
xml | String | The XML to be converted. |
convert_namespace | Integer | When specifying 1, elements including namespaces are also exported to JSON. |
Example
{xmltojson var='json' xml='input'}
zip
Compresses files into a Zip file.
Attributes
Position | Type | Description |
---|---|---|
entries | Array | List of files to compress |
dest | String | The path of the zip file. It must be a path starting with /files/user/ , /files/temp/ , or /files/ltd/ for KurocoFiles, or a path starting with /files/g/ or /files/a for GCS/S3. |
bucket | String | Bucket name. If omitted, the Storage set up in [External System Integration] - [Firebase] will be used. |
callback_batch | String | Batch processing name to be called back after the Zip compression process is completed. |
data | Mixed | Any data to be passed to the callback batch. |
Example
{assign_array var='entries' values=''}
{assign_array var='entry1' values=''}
{append var='entry1' index='name' value='name1'}
{append var='entry1' index='url' value='https://xxxx/xxxx.jpg'}
{append var='entries' value=$entry1}
{assign_array var='entry2' values=''}
{append var='entry2' index='name' value='name2'}
{append var='entry2' index='url' value='https://xxxx/yyyy.jpg'}
{append var='entries' value=$entry2}
{zip entries=$entries dest='/files/user/a.zip' bucket=$bucket}
Support
If you have any other questions, please contact us or check out Our Slack Community.