Controlling Number of Columns for a Bootstrap Site
Hello,
We are trying to build a Responsive Bootstrap site. We have an XSLT script that outputs columns of data on a page. We would like to limit it to three columns per row. Once three columns are done in a row, we would like a new row started.
To that we have started a script that works just fine as long as we do not introduce a count.
I am attaching the XSLT script and XML from the page.
Any suggestions on how best to do it will be greatly appreciated. If it is something you can not help with, please close the ticket.
Thanks,
Akbar
- bootstrap-columns-xslt.txt 1.49 KB
- bootstrap-columns-xml.txt 5.66 KB
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Charlie Holder on 10 Jul, 2014 02:10 PM
Hey Akbar --
In your XML I see four possible columns. Once the row has three columns, should the next row be set to the full 12 column width?
I'm thinking you use a combination of mod, count(), and position() to determine if a new row comes in and how large the columns should be for each row.
Maybe create an
<xsl:template>
that creates a row and create an<xsl:template>
that creates a column. You can pass the XML structure and some information to the templates to determine what parameters should be used (i.e. data and column sizes).If the position() mod 3 is 0, then you've reached the end of your row. At that point you'd want to count how many rows you potentially have left. If it's 3 or more, create a new row with columns of size 4. If it's less, you can take the count() and subtract the position() to get how many are left and then divide out how large the columns should be for what's left.
Let me know if that makes sense or what you think.
Thanks!
2 Posted by aehsan on 10 Jul, 2014 02:26 PM
Hi,
Thanks. Please close this support request. I am not a very advanced user of XSLT. I could not follow your complex explanation. So, I did it in a simpler way.
In order to control the size of the page, we are just allowing six columns, three on each row. So, I did it in a simpler way. I defined a variable with a value of 4. I created two templates with different modes. Went over the same data twice. The first template just creates three rows and the second template the remaining rows. Here is the scripts:
Thanks,
Akbar
3 Posted by Charlie Holder on 10 Jul, 2014 02:38 PM
Will you always have 6 columns? If not, this method might not be ideal because it will always assign a width of 4 to the column. Would you prefer all the rows to be balanced if there are not going to be 3 columns on the row?
4 Posted by aehsan on 10 Jul, 2014 02:58 PM
Hello,
I understand this is not an ideal solution. But for the home page the number of data-rows will not exceed 6. The idea is to make all the rows stackable when we view it on mobile devices and tablets.
My XSLT scripting skills are rather limited and the solution you are recommending is ideal but more complex for me. If you have an example I could look at, that will be great. If not, my simple solution works for now. Once I get better at XSLT scripting, I will try your approach.
Thanks,
Akbar
5 Posted by Charlie Holder on 10 Jul, 2014 03:00 PM
No worries. I'll try to block off some time this afternoon to write some code that might help.
6 Posted by aehsan on 10 Jul, 2014 03:03 PM
Thanks for taking time to do that. That might make our design more flexible.
Akbar
Ryan Griffith closed this discussion on 11 Nov, 2014 06:45 PM.
Charlie Holder re-opened this discussion on 18 Feb, 2015 10:39 PM
7 Posted by Charlie Holder on 18 Feb, 2015 10:39 PM
Hey Akbar --
A situation came up where I needed to revisit this problem. I know it's been a while, but I wanted to share with you the solution that I ended up with.
This code allows for you to have a dynamic number of rows with a dynamic number of content columns in each row. The columns will only balance evenly if you allow for 1-4 WYSIWYGs (set a min/max in the Data Definition). It will automatically assign the correct column width.
Here is the corresponding Data Definition as well:
I will be leading a webinar and I've written a blog post (to be published along with the websinar) on the topic. The webinar is scheduled for March 24, 2015 at 2pm ET. If you're interested in attending I can send you some details once we finalize them.
Thanks.
Tim closed this discussion on 04 May, 2015 06:30 PM.