Joined: Dec 02, 2006 Posts: 1364 Location: Texas, USA
Posted:
Sun Jan 23, 2011 5:47 am
Working on a new theme and looking to convert the block title to a CSS ID.. This is working but I thought I would throw it out there if anyone has ideas for improvements; or a situation where it might fail to produce a valid id.
basically what this does is if the title is not empty, it strips out some unwanted characters, converts to lowercase, replaces invalid characters with hyphens, replaces multiple hyphens with a single hyphen, and trims hyphens from beginning and end of the string. If the title is empty it will generate notitle1, notitle2, etc; to ensure even untitled blocks receive a unique id.
Joined: Aug 29, 2004 Posts: 9136 Location: Arizona
Posted:
Sat Jan 29, 2011 9:22 pm
I am actually curious as to why you would want a unique id on each block? If you are doing this for a jQuery implementation you may still be able to accomplish what you are after by using class names instead, even if you never reference them in your CSS.
Joined: Dec 02, 2006 Posts: 1364 Location: Texas, USA
Posted:
Sat Jan 29, 2011 10:50 pm
Yes this would be for jQuery or styling targeted toward a specific block.. and I agree most times a class would do the job. Working with a few features that require a specific ID, like a block that does not display if JS is disabled, or hiding a block that can then be opened in a modal window inline, or a bottom-side block that has the cool "fixed-floating" effect:
Only registered users can see links on this board! Get registered or login to the forums!
I can probably think of more examples, but that's as far as I've been able to tweak thus far
Joined: Aug 29, 2004 Posts: 9136 Location: Arizona
Posted:
Tue Feb 01, 2011 8:37 pm
Ok, so you definitely need control over the entire block and not just the content. Makes sense.
I suppose you could do it this way. You could also used the "bid" field in the table as you know with 100% certainty that it is unique, just need a consistent suffix in front that starts with a letter instead of a number, like "block" followed by the ID, so like "block5".
My thinking here is that you can then change the block title to anything you want at any point in time and the CSS reference wouldn't change. It is always unique. Even if you use the titles, if you want to change a title, you have to tweak your CSS, so not much added value in the descriptive id names. In addition, if you end up having some kind of configuration page, you'll be reading the nuke_blocks table anyways to get both bid and title.
Just some thoughts since you asked. Of course, in the end, you need to do what makes the most sense to you.
Joined: Dec 02, 2006 Posts: 1364 Location: Texas, USA
Posted:
Tue Feb 01, 2011 9:05 pm
montego wrote:
Ok, so you definitely need control over the entire block and not just the content. Makes sense.
I suppose you could do it this way. You could also used the "bid" field in the table as you know with 100% certainty that it is unique, just need a consistent suffix in front that starts with a letter instead of a number, like "block" followed by the ID, so like "block5".
My thinking here is that you can then change the block title to anything you want at any point in time and the CSS reference wouldn't change. It is always unique. Even if you use the titles, if you want to change a title, you have to tweak your CSS, so not much added value in the descriptive id names. In addition, if you end up having some kind of configuration page, you'll be reading the nuke_blocks table anyways to get both bid and title.
Just some thoughts since you asked. Of course, in the end, you need to do what makes the most sense to you.
thanks for the input
I had similar thoughts originally, as building the ID from the title is not the optimum solution. But I was pretty much working with what was available in the default themesidebox($title, $content) function. It didn't seem very efficient to query the blocks table every time that function is called, so I figured I would deal with the title. I also learned that some modules call themesidebox so in those cases there would be no block id.
In a perfect world I suppose it would be
themesidebox($title, $content, $id)
but whatcha gonna do?
View next topic View previous topic
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum