Smarty Plugin
You can use Smarty plugins for custom processing or batch processing. This summarizes the available Smarty plugins.
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 | |
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β / RC | 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). |
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
}
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.
At this time, you must specify something in the Content-Type of the request header in the format text/***
. Also, please note that even if it is not in JSON format, you need to add the json_encode modifier as in the case of 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
}
Related Document
For information on how to call Kuroco's internal API from custom processing, please refer to Can I call Kuroco's API from a Smarty function?.
api_internal
Requests an API internally and assigns 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 |
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) |
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_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_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 the number of contents that you have marked as your favorite.
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 in reverse chronological order.
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 contents. It must be an array of arrays that have id or table_idval (optional) |
Example
{assign_relation_tag_list
module="topics"
module_id=123
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'}
break
Used inside loops such as foreach or section. When break is executed, the program immediately exits the loop.
Attributes
none
Example
{break}
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 variable related to the date.
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 behavior can be controlled by various options for the width and height of the headless browser.
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 processing called from pre-process or post-process. | 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
Please refer to Scheduling screenshot PDFs of external sites for the detail of how to use generate_pdf
.
github_deploy
Performs building and deploying of front-end sources, with integration to GitHub.
Attributes
Param | Type | Description |
---|---|---|
result_var | String | true: success false: failure |
Example
{github_deploy result_var='res'}
googleanalytics
Get data from Google Analytics.
Attributes
Param | Type | Description |
---|---|---|
var | String | Name of variable to be assigned. |
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(). |
endDate | String | End date of the aggregation period. Can be interpreted by PHP's strtotime(). |
queries | String | Directly specify the query. |
Example
{googleanalytics
var="result"
update_column_slug="ranking"
update_target_dimension="ga:dimension1"
topics_group_id=1}
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 |
msg2 | String | String 2 |
msg3 | String | String 3 |
msg4 | String | String 4 |
Example
{logger msg1=$log1 msg2=$log2}
login
Logs 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}
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 | Name to identify the read_dir block. |
file_var | String | Smarty variable name to store the obtained file name. |
path | String | Path of the directory to be obtained. Specify under /files/user or /files/ltd |
pattern | String | If you want to filter by file path, specify it with a regular expression. |
recursive | Boolean | If you specify true, the contents of the subdirectories are also obtained recursively. |
name_only | Boolean | Get only the file or directory name. |
type | String | Specify 'file' or 'dir' to loop over only files or only directories, respectively. If not specified, both are targeted. |
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 | File path. Specify it as a relative path from TEMP_DIR2. |
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'. |
Example
{read_file name="hoge" path='foo.txt' row="row"}
{$row|escape}
{/read_file}
rcms_match
Call 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
Call the rcms_match_all function.
Attributes
Param | Type | Description |
---|---|---|
var | String | 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
Call 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 |
Example
{rcms_hash var='foo' data='hoge' key='salt'}
refresh_cs
Reset the 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.
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. |
Example
{sendmail
var='result'
to=$mail_to
subject='testmail'
contents="This is test."
from="test@example.com"
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. |
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}
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.
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. |
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.