Page 1 of 1
Smart way to repeat code fragments
Posted: Wed Jan 25, 2017 12:33 pm
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.
Re: Smart way to repeat code fragments
Posted: Wed Jan 25, 2017 4:12 pm
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.
Re: Smart way to repeat code fragments
Posted: Wed Jan 25, 2017 8:58 pm
by Rolf
Not an answer to your question, but perhaps an alternative
https://www.cmscanbesimple.org/blog/the ... gn-manager
Re: Smart way to repeat code fragments
Posted: Thu Jan 26, 2017 9:51 am
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}
Re: Smart way to repeat code fragments
Posted: Thu Jan 26, 2017 7:46 pm
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.

Re: Smart way to repeat code fragments
Posted: Fri Jan 27, 2017 9:35 am
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.
Re: Smart way to repeat code fragments
Posted: Sat Jan 28, 2017 9:23 pm
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.
Re: Smart way to repeat code fragments
Posted: Mon Jan 30, 2017 10:11 am
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.
Re: Smart way to repeat code fragments
Posted: Mon Jan 30, 2017 12:51 pm
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.