Page 1 of 1

Does CMSMS Supports Dynamic Content Blocks in Templates?

Posted: Thu Mar 13, 2025 12:32 pm
by webform
I have a page template with many sections, and each section has a bunch of hard-coded content blocks that are the same in each section (Title, Content, Image, etc.).

I thought I would try to see if I couldn't just define my group of content blocks once and then loop through them in the template, but it doesn't seem possible at first glance?

I get only the first section of content blocks in my page template but the dynamic values ​​for block name, label, etc. are displayed as ((string)$_smarty_tpl->tpl_vars['section']->value['id']). It might not be possible to do it dynamically, so I'll have to stick to hard coding all content blocks?

Example code:

Code: Select all

{assign var='sections' value=[
  ['id' => 'section01', 'legend' => 'Section 1', 'default_class' => 'my-0 py-0 header-stick', 'default_bgcolor' => 'bg-transparent'],
  ['id' => 'section02', 'legend' => 'Section 2', 'default_class' => 'my-0', 'default_bgcolor' => 'bg-transparent'],
  ['id' => 'section03', 'legend' => 'Section 3', 'default_class' => 'my-0', 'default_bgcolor' => 'bg-transparent'],
  ['id' => 'section04', 'legend' => 'Section 4', 'default_class' => 'my-0', 'default_bgcolor' => 'bg-transparent'],
  ['id' => 'section05', 'legend' => 'Section 5', 'default_class' => 'my-0', 'default_bgcolor' => 'bg-transparent'],
  ['id' => 'section06', 'legend' => 'Section 6', 'default_class' => 'my-0', 'default_bgcolor' => 'bg-transparent']
]}

{foreach from=$sections item=section}
	{content_module module='ECB2' field='fieldset_start' label=' ' block="`$section.id`_fieldset" legend="`$section.legend`"}
	{assign var="`$section.id`_id" value="{content block="`$section.id`_id" label='Anchor (section ID)' wysiwyg='false' oneline='true'}" scope="global"}
	{assign var="`$section.id`_class" value="{content block="`$section.id`_class" label='Section Class' wysiwyg='false' oneline='true' default="`$section.default`_class"}" scope="global"}
	{assign var="`$section.id`_style" value="{content block="`$section.id`_style" label='Section Style' wysiwyg='false' oneline='true'}" scope="global"}
	{content_module module='ECB2' field='fieldset_end' label=' ' block="`$section.id`_fieldsetend"}
{/foreach}

Re: Does CMSMS Supports Dynamic Content Blocks in Templates?

Posted: Thu Mar 13, 2025 4:54 pm
by DIGI3
The "group" field in ECB2 (Extended Content Blocks 2) has this feature, it works very well for all types of content fields.

Re: Does CMSMS Supports Dynamic Content Blocks in Templates?

Posted: Thu Mar 13, 2025 5:27 pm
by webform
I already use group fields in the section, but since you can't place a group within a group, I wanted to see if I could make a set of fields in the section dynamic and achieve a similar effect.

I have a collection of fields including an ECB2 group in a section. And since I have 6 sections in the page layout, I have 6 groups of similar fields built up in the following layout structure:

Code: Select all

<section>

	Fields: Various settings fields for the section
	Field: Section Header
	Field: Section Sub Title

		Field: ECB2 Group Row
			- Various content fields for the row

</section>
This is an attempt to build an advanced page layout tool that the website's webmaster can use.
And I was hoping that I could just define a single section and then dynamically generate all the sections I need without having to hardcode 6 groups of the same fields.

Re: Does CMSMS Supports Dynamic Content Blocks in Templates?

Posted: Sun Mar 16, 2025 12:06 am
by tomphantoo
Are the intra-loop assignments needed? Would the following suffice ? (Admin-only usage for ECB2 fieldset* fields)

Code: Select all

{$sections=[
 ['id' => 'section01', 'legend' => 'Section 1', 'default_class' => 'my-0 py-0 header-stick', 'default_bgcolor' => 'bg-transparent'],
 ['id' => 'section02', 'legend' => 'Section 2', 'default_class' => 'my-0', 'default_bgcolor' => 'bg-transparent'],
 ['id' => 'section03', 'legend' => 'Section 3', 'default_class' => 'my-0', 'default_bgcolor' => 'bg-transparent'],
 ['id' => 'section04', 'legend' => 'Section 4', 'default_class' => 'my-0', 'default_bgcolor' => 'bg-transparent'],
 ['id' => 'section05', 'legend' => 'Section 5', 'default_class' => 'my-0', 'default_bgcolor' => 'bg-transparent'],
 ['id' => 'section06', 'legend' => 'Section 6', 'default_class' => 'my-0', 'default_bgcolor' => 'bg-transparent']
]}
{foreach $sections as $section}
 {ECB2 field=admin_fieldset_start label='' block="{$section.id}_fieldset" legend="{$section.legend}"}
 {content block="{$section.id}_id" label='Anchor (section ID)' wysiwyg=false oneline=true}
 {content block="{$section.id}_class" label='Section Class' wysiwyg=false oneline=true default="{$section.default_class"}
 {content block="{$section.id}_style" label='Section Style' wysiwyg=false oneline=true}
 {ECB2 field=admin_fieldset_end label='' block="{$section.id}_fieldsetend"}
{/foreach}

Re: Does CMSMS Supports Dynamic Content Blocks in Templates?

Posted: Sun Mar 16, 2025 4:07 pm
by webform
I have also tried that way, but the result is the same. So Block name for example:

Code: Select all

 block="{$section.id}_id" outputs ((string)$_smarty_tpl->tpl_vars['section']->value['default'])."_id
A simple test where I don't use a foreach loop:

Code: Select all

{assign var='foo' value='foo'}
{content block="`$foo`" label='My Field' wysiwyg='false' oneline='true'}
Gives the result in the page template like:

Code: Select all

<input type="text" size="50" maxlength="255" name="((string)$_smarty_tpl->tpl_vars['foo']->value)" value="">
So apparently you have to hardcode names etc. on fields in page templates before it works.

I was just hoping I could avoid repeating the same code block as many times as I have sections in the page template.