[Zope] stripping .html ending in an id
Tue, 10 Jun 2003 16:13:12 +1200
Ok, I better clarify that a bit. Sorry for the rather abrupt reply, I
didn't read that you were new to Zope... I also missed the fact that you
wanted to capitalise it...
First things first, don't use the old old format <!--#var something-->
any more! <dtml-var something> does the same thing and is the accepted
You can call my script like this: <dtml-var expr="niceid(id)"
capitalize> (the expr="" is so that it knows you're talking Python. You
don't actually *need* the expr=, just the quotes but it helps clarify
when you are using python or just dtml if you stick the expr= on. Was
that confusing? Let me explain with an example:)
<dtml-var a-variable> will return the value in a variable called
<dtml-var expr="a-variable"> uses python to figuire out what you meant -
will return the value in "a" minus the value in "variable"
Next, you could actually just use the "title" field and manually put in
a more appropriate title for each page rather than use my poor script
;). Call it with a nifty method <dtml-var title_or_id> which will revert
back to the id if there is no title.
There is no attribute in dtml-var that can do _title_ capitalization
unfortunately. Here's a newer and better script (no where near the best
it could be but should suffice for you) that I just wrote up. It does
the extention stripping, spacifying and title capitalizing now:
## Script (Python) "niceid"
# strip the extention
dot = id.rfind('.')
if dot != -1:
id = id[:dot]
# turn underscores into spaces
id = id.replace('_', ' ')
# title capitalization
alphabet = list('abcdefghijklmnopqrstuvwxyz')
caps = 1
oldid = id
id = ''
for i in range(len(oldid)):
char = oldid[i].lower()
id += char.upper()
id += char
caps = char not in alphabet
Chris Beaven wrote:
>Try a python script, something like this:
>## Script (Python) "niceid"
>dot = id.rfind('.')
>if dot != -1:
> id = id[:dot]
>id = id.replace('_', ' ')
>Michael Paul Robertson wrote:
>>Hi, I have a quick question to someone out there. It seems that there's
>>easy way to do this (although I'm rather new to zope (~a week), so I
>>be wrong). What I need to do is take the ID variable of a page in a
>>method call and remove the .html suffix in order to use it as the title
>>Here's the content:
>><title><!--#var id spacify capitalize--></title>
>>what it returns for a page call "mission_statement.html" that includes
>>method as a header is
>>It would be ideal if I could capitalize and strip the .html suffix to
>>Sorry for the primitive question, but how can I do this?
>>Thanks for your help.
>>PO Box 11224 email@example.com
>>Stanford CA 94309 650.269.4896
>>``He's done so for 12 years,'' he added. ``So the idea of destroying a
>>rocket, or two rockets, or however many he's going to destroy, says to
>>he's got a lot more weapons to destroy, and why isn't he destroying
>> -- The unbeatable logic of Bush number 42
>>Zope maillist - Zope@zope.org
>>** No cross posts or HTML encoding! **
>>(Related lists -
>Zope maillist - Zope@zope.org
>** No cross posts or HTML encoding! **
>(Related lists -
> http://mail.zope.org/mailman/listinfo/zope-dev )