Reapeating a block multiple times using smarty

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
acore
New Member
New Member
Posts: 7
Joined: Fri Nov 28, 2014 1:07 pm

Reapeating a block multiple times using smarty

Post by acore »

I wanto to repeat a custom set of blocks multiple times, and i would like to write it once and repeat it with a foor loop for example.

There is an example of what I want to do. Supose in my template there is place for data 6 teammates and I want their name and phone number. What i would like to do is something like:

Code: Select all

{for $id=1 to 6}
  {content block="teammate`$id`_name" label="Name of teammate `$id`" oneline="true"} 
  {content block="teammate`$id`_phone" label="Teammate  `$id` phone number" oneline="true"} 
{/for}
Is it possible by any way? or I have to repeat the block six times changing only its number.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Reapeating a block multiple times using smarty

Post by velden »

It can't be done that way.

You could however use a module to accomplish what you like.

That module could be the News module which is installed by default. My personal choice would be ListItExtended (aka LI2 aka ListIt2)
acore
New Member
New Member
Posts: 7
Joined: Fri Nov 28, 2014 1:07 pm

Re: Reapeating a block multiple times using smarty

Post by acore »

But what I want to do is to repeat blocks for the backend, not in the frontend page.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Reapeating a block multiple times using smarty

Post by velden »

acore wrote:But what I want to do is to repeat blocks for the backend, not in the frontend page.
That's not very likely I guess. But even if you´d really want that you can´t do it the way you proposed.

Maybe you should explain what exactly you want to accomplish (not technically, but a use case). Then I tell you to use News Module/ListItExtended module :-)
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: Reapeating a block multiple times using smarty

Post by paulbaker »

Your way (even if it could be done) means going in to the template each time a team member leaves or joins. Not very easy to use.

Using ListIt2 means adding a new team member is a matter of adding a new item in the admin area. When people leave it's even easier, just untick the green status tick box (or delete them completely).

See the screen shot which shows a team within a school from one of my sites, only 4 people remain from the 9 that were entered - see the tick boxes?

Don't be scared of ListIt2, it's dead easy once you get into it. Certainly a lot easier than the Smarty you're trying to do in your template.
Attachments
team.jpg
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation

CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
acore
New Member
New Member
Posts: 7
Joined: Fri Nov 28, 2014 1:07 pm

Re: Reapeating a block multiple times using smarty

Post by acore »

OK. I see what do you say, but I have explained poorly (forget the teammates and their phone numbers). Lets try to do it better:

In short, the template I'm writing have six blocks with the same field structure so what I want to do is define the structure once and tell the template to repeat the structure six times. I think it is important because the structure may change in the future, but there allways be the same for the six blocks so I don't want to rewrite six blocks each time there is a new field.

This is the code I want to change:

Code: Select all

<div class="outerdiv">
  <div id="f0" class="foto">
    <img class="smallFoto" src="{content_image urlonly='1' block='f0_smallimage' dir='fdir' label='Small picture 0}"/>
    <p>{content block='f0_title' label='Title 0' oneline='true'}</p>
    <p>{content block='f0_subtitle' label='Subtitle 0' oneline='true'}</p>
  </div>
  <div id="f1" class="foto">
    <img class="smallFoto" src="{content_image urlonly='1' block='f1_smallimage' dir='fdir' label='Small picture 1}"/>
    <p>{content block='f1_title' label='Title 1' oneline='true'}</p>
    <p>{content block='f1_subtitle' label='Subtitle 1' oneline='true'}</p>
  </div>
  <!--
      ...
  -->
  <div id="f6" class="foto">
    <img class="smallFoto" src="{content_image urlonly='1' block='f6_smallimage' dir='fdir' label='Small picture 6}"/>
    <p>{content block='f6_title' label='Title 6' oneline='true'}</p>
    <p>{content block='f6_subtitle' label='Subtitle 6' oneline='true'}</p>
  </div>

</div>
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Reapeating a block multiple times using smarty

Post by velden »

Use News module or ListItExtended (Listit2, LI2) or ...

It can NOT be done your way!
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: Reapeating a block multiple times using smarty

Post by paulbaker »

acore wrote:so what I want to do is define the structure once and tell the template to repeat the structure six times. I think it is important because the structure may change in the future
You've just described ListIt2 pretty accurately.
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation

CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
Locked

Return to “CMSMS Core”