Smart way to repeat code fragments

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.
Post Reply
acore
New Member
New Member
Posts: 7
Joined: Fri Nov 28, 2014 1:07 pm

Smart way to repeat code fragments

Post by acore »

Hi!
I'm looking for a smart way of writing less code. What I want to do is described in this post (viewtopic.php?f=8&t=71862) and the solution gave was not good for me (ListIt2 is not easy to use by end users, and now is deprecated). Also it was referred to cmsms1, so I'm wondering if cmsms2 has something better in this matter.

In short, what I want to do is define an template with a number of blocks surrounded by same html structure; something like:

Code: Select all

{for $foo=1 to 10}
    <div id="block{$foo}">
        {content block="content{$foo}"}
    </div>
{/for}
Change <div> and </div> by a complex html structure. That way if the html structure get modified, I have to change it only once.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Smart way to repeat code fragments

Post by calguy1000 »

You cannot do this in content page templates.

The best solution, if you want the editor to be able to enter structured data, with validation and to display a subset of them based on criteria in a page template, is simply to use a module like LISE and perhaps CGContentUtils.

Use LISE to create an 'instance' for the structured data. Your editor can manipulate the data there.

In your page template you can add content blocks and fields to allow the editor to select how many records to display, and from which instance (and possibly other criteria). and then you use the summary template from your instance to render that data.

LISE instances have functionality for filtering, sorting and rendering, input data validation, and more. You can display the same data in multiple places, multiple different ways. And you can create many many instances to allow entering different types of data.

Modules like CGContentUtils provide
numerous different content block fields that you can use in your page templates to allow an editor to select the data to display.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: Smart way to repeat code fragments

Post by Rolf »

Not an answer to your question, but perhaps an alternative
https://www.cmscanbesimple.org/blog/the ... gn-manager
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
acore
New Member
New Member
Posts: 7
Joined: Fri Nov 28, 2014 1:07 pm

Re: Smart way to repeat code fragments

Post by acore »

Thanks to all of you.

Eventually I'm going with a third solution.

LISE is quite powerful, but I can not figure any way to explain it to an end user on a easy way. I mean, content in LISE is outside of the page hierarchy, and end user must know about lise tags to and so.

In the other hand, I'm using yet template inheritance. Great feature in CMSMS2.

The solution I'm using right now is based in variable-variable names of smarty3:
I have to manually define the content blocks in the beginning of the template, and assign them to vars like $content1, $content1image1, $content1image2, $content2, $content2image1, $content2image2... I define also a variable with the number of blocks and images per block ($numberOfBlocks and $numberOfImages)
Then the structure of the template looks something like:

Code: Select all

{for $indexOfBlocks=1 to $numberOfBlocks}
  <div>
  <p>{$content{$indexOfBlocks}}</p>
  {for $indexOfImages=1 to $numberOfImages}
    {$content{$indexOfBlocks}image{$indexOfImages}}
  {/for}
  </div>
{/for}
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: Smart way to repeat code fragments

Post by paulbaker »

I mean, content in LISE is outside of the page hierarchy,
Agreed.
and end user must know about lise tags to and so.
What do you mean by LISE tags? I use LISE quite a bit and don't think I have ever used tags.
I have to manually define the content blocks
It sounds like you have to manually set the number of "things" in your list in your template. You don't have to do that with LISE. The content editor adds/edits/deletes/makes active/inactive his "things". They show up (or don't show up) on the front end.

But if your solution works for you then hey that's one of the great things about CMSMS - there's often more than one solution. ;)
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: Smart way to repeat code fragments

Post by acore »

paulbaker wrote:
What do you mean by LISE tags? I use LISE quite a bit and don't think I have ever used tags.
Maybe it's because I haven't found a proper example of using LISE, can you point me at any article or documentation?

I have another question about LISE. My website is multilingual and I'm using MleCMS (2.0-alpha2) for that. Since MleCMS is based in an hierarchy disposition of languages, it will not work with LISE isn't it?

PD: If you have any other better suggestion to build a multilingual site, I'll be very glad to hear it. I'm not very confortable using a alpha2 version of a module.
User avatar
Franck
Dev Team Member
Dev Team Member
Posts: 260
Joined: Tue Jun 12, 2007 1:29 pm

Re: Smart way to repeat code fragments

Post by Franck »

acore wrote:PD: If you have any other better suggestion to build a multilingual site, I'll be very glad to hear it. I'm not very confortable using a alpha2 version of a module.
Even though it's an alpha version, no significant bug has been reported (except yours :) ), and it's being used on several websites without any problem. So I guess it'll become a beta or a stable version soon.
acore
New Member
New Member
Posts: 7
Joined: Fri Nov 28, 2014 1:07 pm

Re: Smart way to repeat code fragments

Post by acore »

Tomek wrote:
acore wrote:PD: If you have any other better suggestion to build a multilingual site, I'll be very glad to hear it. I'm not very confortable using a alpha2 version of a module.
Even though it's an alpha version, no significant bug has been reported (except yours :) ), and it's being used on several websites without any problem. So I guess it'll become a beta or a stable version soon.
I have no bug at all with mle. I was asking if MLE will work with LISE.
User avatar
Franck
Dev Team Member
Dev Team Member
Posts: 260
Joined: Tue Jun 12, 2007 1:29 pm

Re: Smart way to repeat code fragments

Post by Franck »

Oh yes, I misread, sorry. Can't say for now, haven't upgraded the only site using LI2 + MleCMS to V2 / Lise / MleCMS2 yet. But I guess it should work as previously.
FYI, I use a field definition named "language" and one template by language to sort them.
Post Reply

Return to “CMSMS Core”