Can't get scripting file to insert div after 2 and 3 childpage
Hi,
I have some problems with my script...
I want it to take childpages of the current page and list them with 3 in each row, and then insert a div that clear the float and makes some space between the two rows, and it's working well, the problem begins now because it's a responsive website and when a phone is viewing the site, i want to the display 2 in each row, and then the div that makes space. So i made this script
In your case I think you should take a look at .InGroupsOf([int]) if you don´t know it already. By using this you´re able to group items, e.g three items in each row. The integer value specifies the size of the groups.
@* return in groups of 3 *@ @foreach(var group in Model.Children.InGroupsOf(3)){ <div class="row"> @foreach(var item in group){ <div>@item.Name</div> } </div> }
I hope this can help you to do what you want easier and maybe do your code more readable.
I was trying to say, that maybe the InGroupsOf([int]) function you help you out :-) and if you don´t already knew it I think that you should know it then :)
Suggestion: use a non-programming-related solution and drastically simplify things.
Just loop through one, and stop keeping track of count --- you don't need the "first" and "last" classes! Instead, using CSS3 and media queries, you can use nth-child selector to clear previous floats, which would be every other element (2n+1) on a phone or every third element on desktop (3n+1).
Just a quick idea to consider. Best of luck to you!
Can't get scripting file to insert div after 2 and 3 childpage
Hi,
I have some problems with my script...
I want it to take childpages of the current page and list them with 3 in each row, and then insert a div that clear the float and makes some space between the two rows, and it's working well, the problem begins now because it's a responsive website and when a phone is viewing the site, i want to the display 2 in each row, and then the div that makes space. So i made this script
This works great on desktop and tablets but not phones, it makes this HTML
But i have figured out how i can make it look nice on all three platforms with this HTML, but i can't get the script to make it like this...
So can some of you help me with my script so it figures out how to make the html below or something that's works like i have described
// Anders
Hi Anders,
In your case I think you should take a look at .InGroupsOf([int]) if you don´t know it already. By using this you´re able to group items, e.g three items in each row. The integer value specifies the size of the groups.
I hope this can help you to do what you want easier and maybe do your code more readable.
Hope the InGroupsOf fuction can help you.
/Dennis
Okay, thanks :-)
But i still can't see how this is thhelp because it has to be a row with three on desktop and tablet and a row with two on phone?
// Anders
Hi Anders,
I was trying to say, that maybe the InGroupsOf([int]) function you help you out :-) and if you don´t already knew it I think that you should know it then :)
Here is a small example: https://gist.github.com/nul800sebastiaan/1067257 that use InGroupsOf.
/Dennis
Suggestion: use a non-programming-related solution and drastically simplify things.
Just loop through one, and stop keeping track of
count
--- you don't need the "first" and "last" classes! Instead, using CSS3 and media queries, you can usenth-child
selector to clear previous floats, which would be every other element (2n+1) on a phone or every third element on desktop (3n+1).Just a quick idea to consider. Best of luck to you!
It's working now! :)
I used the InGroupsOf(3), and two counters and i got it to work! :D
is working on a reply...