Developer forum
E-mail notifications
Loops
I was wondering what kind of options we have within loops, for example; add extra tags after 3 iterations and so forth.
Replies
ml@acph.dk wrote:
Hi there,
I was wondering what kind of options we have within loops, for example; add extra tags after 3 iterations and so forth.
Hi
You have no options regarding adding tags.
Loops is just a way of cutting down the amount of templates.
// Dammark
When coding with templates in custom modules you can add tags - and also only let them show when you are in 3rd iteration:
Dim tmpl As New Templatev2.Template("DwCustomModule/" & prop.Value("template"))
tmpl.SetTag("PageID", pv.ID)
Dim sql As String = String.Empty
sql = "SELECT * FROM [Module] WHERE [ModuleAccess] = " & Database.SqlBool(True)
Dim i As Integer = 1
Using dr As IDataReader = Database.getDataReader(sql, "Dynamic.mdb")
Do While dr.Read
Dim myLoop As Templatev2.Template = tmpl.GetLoop("Modules")
'myLoop.SetTag("SystemName", dr.Item("ModuleSystemName").ToString)
'myLoop.SetTag("ModuleName", dr.Item("ModuleName").ToString)
myLoop.SetTags(dr)
If i > 3 Then
myLoop.SetTag("MoreThan3", i)
End If
myLoop.CommitLoop()
i += 1
Loop
End Using
tmpl.SetTag("SomeTag", "Some value")
'tmpl.GenerateTemplate(True)
Return tmpl.Output
Hi,
I have a wild idea, though may not be very reliable/applicable. What if you use a javascript variable that will be incremented each time the loop runs, and every 3 or 4 incrementions, outputs something?
I understand this may require a lot of processing on the client side, but could work as a solution to someone, don't you think?
//nuno
nuno wrote:Hi,
I have a wild idea, though may not be very reliable/applicable. What if you use a javascript variable that will be incremented each time the loop runs, and every 3 or 4 incrementions, outputs something?
I understand this may require a lot of processing on the client side, but could work as a solution to someone, don't you think?
//nuno
I've used jQuery to parse the bits I need, here is my example:
the jquery bit:
$(document).ready(function(){
var productsItems = $('DIV.products/DIV#productPaging/DIV.productWrapper');
var numberOfPages = Math.ceil(productsItems.length / 3);
for (var i = 1; i <= numberOfPages; i++) {
$('').insertAfter("div.defaultHeader");
}
for (var i = 1; i <= numberOfPages; i++) {
$('div#productPage'+(i-1)).append($('DIV.products/DIV#productPaging/DIV.productWrapper').lt(3).gt(-1).remove());
}
$('div#productPaging').remove();
});
You must be logged in to post in the forum