Search the FirstSpirit Knowledge Base
Hi there,
Good Morning. My current FirstSpirit Server version is 5.2.212.71463.
I have a page template which loops through each row in Datasource and calls the render template as below for each row and assigns the output of render template to a List. I later use this list to replace specific patterns in the External html content for preview mode. Snippet from Page Template and Table template are below.
-- PageTemplate : HomePage
<CMS_HEADER>
<CMS_FUNCTION name="contentSelect" resultname="fr_pt_menus">
<CMS_PARAM name="schema" value="standard"/>
<QUERY entityType="menus"/>
</CMS_FUNCTION>
</CMS_HEADER>
$CMS_SET(stringToReplace, [])$
$CMS_SET(stringToInsert, [])$
$CMS_FOR(for_each_menu, fr_pt_menus)$
$CMS_SET(void, stringToReplace.add("<!-- CMS-PREVIEW-MEGAMENU-TOPCAT_"+for_each_menu.categories.category_id+" -->"))$
$CMS_SET(set_row_menu, for_each_menu)$ $-- Setting Each Row of the datasource to set_row_menu --$
$CMS_SET(stringToInsert[stringToReplace.size-1])$
$CMS_RENDER(template:"channel_import", type:"tt", uid:"standard.menus")$
$CMS_END_SET$
$CMS_SET(set_row_menu, "")$ $-- Reset the variable --$
$CMS_END_FOR$
$CMS_VALUE("stringToInsert:"+stringToInsert)$
This render template $CMS_RENDER(template:"channel_import", type:"tt", uid:"standard.menus")$ essentially will call the generation channel of any object (in this case a table template), per below:
$CMS_VALUE(#global.userService.getStore(class("de.espirit.firstspirit.access.store.Store$Type").TEMPLATESTORE,false).getStoreElement(uid, class("de.espirit.firstspirit.access.store.IDProvider$UidType").TEMPLATESTORE_SCHEMA).getTemplateDocument(#global.project.templateSets.get(0)))$
Which will call the generation channel of the table template named "standard.menus", whose generation channel is the HTML snippet of each Category Menu on the website.
-- Table Template : standard.menus
$CMS_IF(!#row.isEmpty)$
$CMS_SET(set_row_menu, #row)$
$CMS_END_IF$
<li class="nav-item__list-group">
<ul>
$CMS_FOR(for_menu_link, set_row_menu.links_list)$
<li>$CMS_VALUE(for_menu_link)$</li>
$CMS_END_FOR$
</ul>
</li>
--- Output From Page Template:
stringToInsert:[ $CMS_RENDER(template:"channel_import", type:"tt", uid:"standard.menus")$
, $CMS_RENDER(template:"channel_import", type:"tt", uid:"standard.menus")$ ]
As seen above FirstSpirit is storing the actual String and rendering it later. How do i force CMS_SET to store the actual rendered markup of the above render template and not the actual string CMS_RENDER ?
As a result of this, I am not able to access each row (variable set_row_menu) from datasource in the table template, which is being looped through in the page template.
Thanks
Upendra
Hi Upendra,
the "two part" CMS_SET does not directly evaluate its content and assigns that content to a variable. Instead, it defines a "TemplateFragment" that is evaluated later when calling CMS_VALUE on the variable. As a result, the output uses the values of all variables they have at the moment of the CMS_VALUE call.
To force the evaluation you can use a temporary variable and .toString():
$CMS_SET(set_temp)$
$CMS_RENDER(template:"channel_import", type:"tt", uid:"standard.menus")$
$CMS_END_SET$
$CMS_SET(stringToInsert[stringToReplace.size-1], set_temp.toString())$
Michael
Hi Upendra,
the "two part" CMS_SET does not directly evaluate its content and assigns that content to a variable. Instead, it defines a "TemplateFragment" that is evaluated later when calling CMS_VALUE on the variable. As a result, the output uses the values of all variables they have at the moment of the CMS_VALUE call.
To force the evaluation you can use a temporary variable and .toString():
$CMS_SET(set_temp)$
$CMS_RENDER(template:"channel_import", type:"tt", uid:"standard.menus")$
$CMS_END_SET$
$CMS_SET(stringToInsert[stringToReplace.size-1], set_temp.toString())$
Michael
Hi Michael,
Perfect! That did the trick! Thank you.
Is there a specific documentation explaining what happens inside each of the CMS_ instruction or an overview of the internals of each of the CMS_ calls. I could not find this information you specified in the documentation.
Regards
Upendra