Skip to main content

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

ParamTypeDescription
varStringThe variable name to which the addition is performed. The result of the addition is also stored in the same variable name. (required)
valueIntNumber

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

ItemUsageExampleNote
endpointEndpoint (required)https://example.com/brah/
methodMethodPOST/GET/PATCH/PURGE/PUT/DELETE
queryQuery stringparam1=hoge&param2=foo
queriesQuery array$params
json_bodyRequest JSON body{param1:"hoge",param2:"foo"}
bodyRequest body
filesFile['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.
headersRequest headers['Host: localhost','user-agent: hoge']Specify as an array.
cache_timeCache time (minutes)20
varStorage variable of the responseresponse
json_varStorage variable of the responseresponseIf the response is in JSON format, the decoded value is stored.
resp_header_varResponse header storage variableheaderThe response headers will be stored in an array format.
dl_flgDownload flagtrue/falseIf true, the response is saved as a file in the Kuroco temporary area.
status_var0: Failure 1: SuccessstatusReturns whether the request was successful or not.
timeoutTimeout60Specify the timeout (in seconds).
sslcertsecret key of mTLS client certificateSSLCERT001Specify a Kuroco secret key of mTLS client certificate
sslkeysecret key of mTLS client secret keySSLKEY001Specify a Kuroco secret key of mTLS client secret key
cainfosecret key of mTLS Server CA infoCAINFO001Specify 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

ParamTypeDescription
endpointStringEndpoint (required)
methodStringMethod (POST/GET)
queryStringQuery string
queriesArrayQuery array
headersArrayRequest headers
cache_timeIntegerCache time (minutes)
varStringVariable name to store the response
status_varString0:Failed 1:Success
member_idIntegerExecute as the specified login member
*Note: Cannot be used in conjunction with the 'direct' parameter.
use_current_sessionBooleanExecute API request by taking over the current session
directBooleanExecute 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

ParamTypeDescription
varStringThe variable name to store the result (required)
modelStringModel
methodStringMethod (operation)
versionIntegerVersion
request_paramsArrayRequest variables
method_paramsArrayMethod 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

ParamTypeDescription
endpointStringEndpoint (required)
methodStringHTTP Method (POST/GET)
queryStringQuery string
queriesArrayQuery array
headersArrayRequest headers
filesArrayUploaded files
varStringVariable to store the response
status_varString0: Failure 1: Success
member_idIntegerExecute as the specified login member
use_current_sessionBooleanExecute 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

ParamTypeDescription
varStringThe name of the array (required)
valueStringThe name of the object or array to add (required)
indexIntegerThe 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

ParamTypeDescription
dg_keyStringThe key to generate DG_CODE
dg_idStringThe id to generate DG_CODE
api_keyStringThe key to generate sid request (required)
varArrayThe name of the returning array
jwt_dataArrayJWT data
member_idIntegerMember ID
expireIntegerExpiration 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

ParamTypeDescription
varStringThe name of the variable to assign the array to (required)
valuesStringThe values to store in the array. A string separated by a delimiter
delimiterStringThe delimiter to use to split the values specified in 'values'. The default is a comma
keysStringIf 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

ParamTypeDescription
varStringName of the assigned diff array
array1ArrayArray 1
array2ArrayArray 2
diff_modeStringMode 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

ParamTypeDescription
varStringName of the assigned intersect array
array1StringArray 1
array2StringArray 2
intersect_modeStringMode 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

ParamTypeDescription
varStringThe name of the return variable (required)
fromStringOriginal array
keyStringkey name
valueStringvalue

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

ParamTypeDescription
csvtable_idIntegerThe ID of the master (required)
varStringThe name of the return variable (required)
get_key_valBooleanEnable the use of optional parameters. (optional)
key_idxInteger/ArrayReturn dimension or dimensions to be returned. (optional)
value_idxIntegerReturn dimension or dimensions to be returned. (optional)
multipleBooleanDistinguish by the number of dimensions. (optional)
langStringIf it supports multiple languages, specify the language such as "ja", "en", etc.
table_nameStringThe 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

ParamTypeDescription
module_typeStringThe module name. Specify one of "topics","comment","member","tag","csvtable", or "ec_product". The default is "topics".
module_idIntegerThe ID of the specified module.
varStringThe name of the variable to store the result (required).
timeStringThe strtotime format.
formatStringThe 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

ParamTypeDescription
varStringVariable name to store global variables.
keyStringKey for global variables.
valueMixedValue of the global variable.
unsetBoolTo 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

ParamTypeDescription
group_idIntegerGroup ID (required)
varStringThe name of the variable to store the result (required).
langStringThe 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

ParamTypeDescription
module_typeStringThe name of the module. Specify one of "topics", "comment", "member", "tag", "csvtable", or "ec_product". The default is "topics".
module_idIntegerThe ID of the specified module.
varStringThe variable name to store the result (required).
cookie_flgIntegerThe flag for getting favorite contents with cookie management.
action_typeStringThe 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

ParamTypeDescription
varStringThe name of the variable to store the result (Required)
member_idIntThe member ID of the value to retrieve (Required)|
open_by_groupBooleanWhen false, the viewing permission is ignored. The default value is true.
open_flgInt(Deprecated) When -1, only information about members who can view is retrievable.
assign_group_flgBooleanWhether 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

ParamTypeDescription
module_idStringThe ID of the module where the content is specified.
module_typeStringThe name of the module. Specify either "topics", "comment", "member", "tag", "csvtable", or "ec_product". Default is "topics".
varBooleanThe variable name to store the result (required).
new_order_flgStringWhen set to false, the results are returned in ascending order.
cntStringLimits 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

ParamTypeDescription
moduleStringModule name
module_idIntegerID in the specified module (required)
varStringVariable name to store the result (required)
tag_category_idIntegerIf you want to narrow down by tag category, specify the tag category ID (optional)
tag_relation_listArrayArray 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

ParamTypeDescription
varStringThe name of the variable to store the result in (required)
langStringLanguage code setting
tree_flgBooleanFlag 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

ParamTypeDescription
varStringThe name of the variable to store the result in (required)
category_idIntegerThe ID of the category tag to specify (required)
orderArrayAn 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

ParamTypeDescription
varStringThe variable name to store the result (required).
topics_group_idIntegerThe topics_group_id of the category group to be specified (required).
langStringLanguage 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

ParamTypeDescription
varStringVariable name to store the result (required)
topics_idIntegerID of the content (required)
idIntegerID of the content (Specify either topics_id or id. If both are present, topics_id will be given priority.)
langStringLanguage setting
chk_open_flgBooleanWhether 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

ParamTypeDescription
typeStringSpecify "full"
memoStringMemo for the backup
result_varStringVariable 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

ParamTypeDescription
backup_idStringSpecify the backup ID
start_dateStringSpecify the start date of the backup period to delete
end_dateStringSpecify the end date of the backup period to delete
result_varStringVariable 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

ParamTypeDescription
from_site_keyStringSite key of synchronization source
to_site_keyStringSite key of synchronization destination
If no specific designation is provided, it will synchronize with your own website.
sync_typeInteger1: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

ParamTypeDescription
batch_idIntegerBatch ID (Either this value or name is required)
nameStringSlug of batch (Either this value or batch_id is required)
moduleStringTarget module name (It used when you register default batch)
ext_dataArrayData to pass to the registered batch.
varStringVariable name which stores registered batch id

Example

{batch batch_id='1234' ext_data=$ext_data}

child_site

Get data of a child site.

Attributes

ParamTypeDescription
site_keyStringSite key (required)
varStringName 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}

Get/set Cookie.

Attributes

ParamTypeDescription
varStringVariable name
keyStringKey
valueStringString value
expiresIntegerExpiration date of the cookie in days
overwriteIntegerOverwrite flag

Example

{cookie key="foo" value="test"}

date

Assigns a date variable.

Attributes

ParamTypeDescription
varStringVariable name to store the result (required)
timeStringstrtotime format
formatStringFormat

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

ParamTypeDescription
varStringVariable name to store the result (required)
idIntegerID of the custom function
nameStringIdentifier 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

ParamTypeDescription
varStringVariable name to store the result (required)
urlStringURL of the function (required)
sa_secret_nameStringName 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

ParamTypeDescription
varStringVariable name to store the result (required)
topicStringTopic name to deliver the message to (required)
messageAnyMessage to be delivered (required)
projectStringGCP project name
sa_secret_nameStringSecret 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

ParamTypeDescription
varStringVariable name to store the result
pathStringPath to the file on S3/GCS to retrieve
urlStringURL of the file to retrieve
bucketStringBucket name on S3/GCS where the file to retrieve is located
saveBooleanWhether 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_pathStringFile 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

ItemDescriptionExample
urlSpecify the URL of the page to convert to PDF.https://www.diverta.co.jp
pathSpecify 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
optionSpecify the options for PDF conversion.
browser_widthSpecify the browser width.browser_width=1280
browser_heightSpecify the browser height.browser_height=2560
sleepSpecify the waiting time (in milliseconds) until the specified page is captured.sleep=1000
uaSpecify 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"
formatSpecify the format of the file to be saved. pdf, png, jpeg, jpg, and webp are available.format="png"
cookieSpecify 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
domainSpecify the domain of the cookie.domain="www.diverta.co.jp"
overwriteSpecify whether to overwrite the file if it already exists.overwrite=1
callback_batchSpecify 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"
dataYou 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

ParamTypeDescription
result_varStringtrue: 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

ParamTypeDescription
varStringVariable name to assign data retrieved from Google Analytics
updated_topics_idsArrayAn array of content IDs where counter values have been set
update_column_slugStringSlug of the column to update.
update_column_indexIntegerIndex of the column to update.
update_target_metricStringMetric to use for update.
update_target_dimensionStringCustom dimension to update.
topics_group_idIntegerContent definition ID.
startDateStringStart date of the aggregation period. Can be interpreted by PHP's strtotime().Default value is a 7 days before.
endDateStringEnd date of the aggregation period. Can be interpreted by PHP's strtotime().Default value is today.
queriesStringDirectly 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

ParamTypeDescription
msg1StringString 1(within 1KB)
msg2StringString 2(within 1KB)
msg3StringString 3(within 1KB)
msg4StringString 4(within 1KB)

Example

{logger msg1=$log1 msg2=$log2}

login

Log in.

Attributes

ParamTypeDescription
member_idIntegerMember ID
overwriteBooleanWhether 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

ParamTypeDescription
varStringThe variable name to store the result (required)
cntIntegerThe number of IDs to be drawn
duplicateIntegerThe number of duplicates
idsArrayTarget IDs (required)
exclude_idsArrayExcluded 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

PositionTypeDescription
1Stringformat

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

PositionTypeDescription
1Stringformat

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

ParamTypeDescription
api_endpointStringSpecify the URL of the endpoint.
moduleStringSpecify the module name. Currently, it supports topics and csvtable and all (required).
topics_group_idintIf the module name is specified as topics, specify the content definition ID.
csvtable_idintIf 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

ParamTypeDescription
tmp_pathStringThe path of the file to upload. Specify a file in the temporary folder.
pathStringThe destination path of the file.
valueStringThe content to write to the file.
files_pathStringThe path on KurocoFiles (/files/(user
bucketStringThe 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

ParamTypeDescription
nameStringThe name used to identify the read_dir block.
file_varObjectThe 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.
pathStringThe path of the target directory to retrieve. Specify either /files/user or /files/ltd as subdirectories.
patternStringIf you want to filter by file path, specify a regular expression here.
recursiveBooleanWhen set to true, it will recursively retrieve the contents of subdirectories.
name_onlyBooleanWhen set to true, the file_var variable will return only the file path as a string.
typeStringSpecify '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

ParamTypeDescription
nameStringName to identify the read_file block.
pathStringpecify the file path as a relative path from /files/. The accessible directories are as follows:
  • /files/user/
  • /files/ltd/
  • /files/topics/Release version: βversion
  • /files/member/Release version: βversion
rowStringSmarty variable to store one line of read data.
typeStringFile format. Specify 'txt', 'csv', or 'jsonl'. If not specified, the default is 'txt'.
ignore_permissionRelease version: βversionBooleanIf 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

ParamTypeDescription
varStringThe variable name to store the result (required)
patternStringThe pattern to search for
subjectStringThe input string
flagsIntegerYou 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.
offsetIntegerThe 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

ParamTypeDescription
varArrayThe variable name to store the result (required).
patternStringThe string representing the pattern to search for.
subjectStringThe input string.
flagsIntegerYou 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.
offsetIntegerThe 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

ParamTypeDescription
varStringName of the variable to store the result (required)
algoStringAlgorithm (default=sha256)
dataStringTarget string (required)
keyStringSecret key for HMAC method
binaryBooleanWhen 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

ParamTypeDescription
addArrayArray 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

ParamTypeDescription
pathStringPath of the directory to remove.
status_varStringName 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

ParamTypeDescription
pathStringThe path of the file to be deleted
bucketStringThe name of the S3/GCS bucket where the file is located
status_varStringThe 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

ParamTypeDescription
src_pathStringSource path
dest_pathStringDestination path

Example

{rename_file src_path=$src_path dest_path=$dest_path}

return

Exits the custom function with an optional value.

Attributes

ParamTypeDescription
valueMixedA 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

ParamTypeDescription
valueStringContent to be saved.
varStringVariable name to store the result.

Example

{save_file var='path' value=$value}

secret

Retrieves a secret.

Attributes

ParamTypeDescription
varStringThe variable name to store the result (required)
keyStringThe 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

ParamTypeDescription
varStringThe variable name to store the result. If successful, true will be stored; otherwise, false.
toStringThe destination email address.
subjectStringThe email subject.
contentsStringThe email body.
fromStringThe FROM address.
from_nmStringThe sender name of the FROM address.
mail_templateStringThe identifier of the message template.
Variable NameStringSpecifies 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

ParamTypeDescription
varStringThe 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

ParamTypeDescription
varStringThe variable name to store the result in.
channelStringThe ID of the channel.
tsStringThe 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

ParamTypeDescription
varStringThe name of the variable to store the result. If successful, it will store true, otherwise false.
channelStringThe ID of the channel to post the message to.
usersArrayAn array of user IDs to mention in the message.
textStringThe text of the message.
thread_tsStringThe 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

ParamTypeDescription
varArrayThe variable name to store the result. If the process fails, false is stored.
teamStringThe 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

ParamTypeDescription
msIntegerTime 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

ParamTypeDescription
varStringName of the variable to store the result.
pathStringPath of the file on S3/GCS.
expireStringExpiration 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

ParamTypeDescription
varStringVariable name to store the result (required)
timestampInt|StringTimestamp
formatStringFormat

Example

{strtodate var='today' timestamp='today' format='Ymd'}

subtract

Subtracts a number from a variable.

Attributes

ParamTypeDescription
varStringThe variable name to store the result (required)
valueIntThe number to subtract from the variable.

Example

{subtract var='i' value=5}

unzip

Unzips a zip file.

Attributes

ParamTypeDescription
srcStringThe path to the zip file to be extracted. Must be a URL starting with https:// or a path on a cloud storage.
destStringThe 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/).
bucketStringThe name of the bucket. If omitted, the storage specified in [External System Integration] - [Firebase] is used.
callback_batchStringThe name of the batch processing to be called back after the zip extraction is complete.
dataMixedAny data. Passed to the callback batch.
overwriteIntegerWhether to overwrite the file with the same name in the destination folder if it already exists. 0 or 1.
detect_orderArrayYou 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

ParamTypeDescription
varStringVariable 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

PositionTypeDescription
1IntegerThe format type of the result (default=1).
2IntegerThe 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

PositionTypeDescription
1Arraylist

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

PositionTypeDescription
1StringThis is the regular expression to be replaced.
2StringThis 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

PositionTypeDescription
targetArrayThe 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

PositionTypeDescription
targetArrayThe array to be converted (required).

Example

{assign var='foo' value=$bar|@to_object}

twitter_post_message

Sends a message to Twitter.

Attributes

PositionTypeDescription
varStringThe variable name to store the result.
textStringThe 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

ParamTypeDescription
varStringThe variable name to store the result.
valueIntegerThe value you want to set (Required)
topics_group_idIntegerContent definition ID (Required)
slugStringTarget content's ID/Slug (Required)
ext_slugStringTarget column's ID/Slug (Required)
indexIntegersequence 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

PositionTypeDescription
pathStringThe file path. If omitted, the file is automatically written to a temporary area with a unique file name.
varStringThe variable name to store the temporary file path that was written (required).
valueString | ArrayThe data to be written. If an array is specified, it will be written in CSV format.
is_appendIntegerAppend 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

ParamTypeDescription
varStringThe variable name to store the result. (required)
xmlStringThe XML to be converted.
convert_namespaceIntegerWhen specifying 1, elements including namespaces are also exported to JSON.

Example

{xmltojson var='json' xml='input'}

zip

Compresses files into a Zip file.

Attributes

PositionTypeDescription
entriesArrayList of files to compress
destStringThe 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.
bucketStringBucket name. If omitted, the Storage set up in [External System Integration] - [Firebase] will be used.
callback_batchStringBatch processing name to be called back after the Zip compression process is completed.
dataMixedAny 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.