MakePathFromTemplate
string MakePathFromTemplate( string template , array arParams );
The method replaces substrings #SITE_DIR#, #SITE#, #SERVER_NAME# in the template with the values of system constants SITE_DIR, SITE_ID, SITE_SERVER_NAME, respectively. State method.
Additionally, this method replaces all "#arParams array key#" type substrings to the corresponding values as per arParams array rules.
Parameters
Parameter | Description |
---|---|
template | Path template that will contain substrings type "#.....#". |
arParams | Array of replacements. The format as follows:
array( "key1" => "value 1", "key2" => "value 2", * * * )Substring "#key1#" in the template is replaced with the "value 1", "#key2#" - replaced with the "value 2" and etc. Optional parameter from version 11.0.16. |
Returned value
Resulting string after replacements from template.
Example
// Component input parameter - path template $arParams["SECTION_PAGE_TEMPLATE2"] = "/#IBLOCK_ID#/#SECTION_ID#.php?s=#SITE#"; // Values calculated in the component: $IBLOCK_ID = 3; $SECTION_ID = 982; // Generate path based both on this template and // values, calculated in the component $pagePath = CComponentEngine::MakePathFromTemplate( $arParams["SECTION_PAGE_TEMPLATE2"], array( "IBLOCK_ID" => $IBLOCK_ID, "SECTION_ID" => $SECTION_ID ) ); // The variable $pagePath will contain the following string: $pagePath = "/3/982.php?s=ru";
© «Bitrix24», 2001-2024