Hi all, I am constructing a website using webgen. By changing default.template, I could finally insert a TOC in the side bar with {menu: {used_nodes: fragments}}. Now, I want to do something more complex: Given any page, webgen should decide how to generate the table of content using the following algorithm: - If the number of h1 headings is greater than 1, i.e. > 1. Then use all h1 headings as TOC - Else find the number of headings in lower level, until there is a level of headings in which there are more than 1 headings, use headings in that level in TOC. - Else do not generate TOC. More precisely, given the following page content: # Title ## Section 1 ## Section 2 The TOC should contain: * Section 1 * Section 2 (and its corresponding links) If the page is: # Section 1 # Section 1 The TOC should be: * Section 1 * Section 2 If the page is: # There is only one title foo bar blah blah... Then there is not TOC. If there any way to do it by changing the template? I didn''t find any document about how to write templates (something like how to write condition stmt, loop stmt and how to find available variables etc.) I would be appreciate if anyone could point me a link or a solution. Regards, -Monnand
Anyone? Thought? Sorry for disturbing you all. But is there any comment on my question? -Monnand monnand wrote, On 05/03/2012 10:18 PM:> Hi all, > > I am constructing a website using webgen. By changing default.template, > I could finally insert a TOC in the side bar with {menu: {used_nodes: > fragments}}. Now, I want to do something more complex: > > Given any page, webgen should decide how to generate the table of > content using the following algorithm: > > - If the number of h1 headings is greater than 1, i.e.> 1. Then use all > h1 headings as TOC > - Else find the number of headings in lower level, until there is a > level of headings in which there are more than 1 headings, use headings > in that level in TOC. > - Else do not generate TOC. > > More precisely, given the following page content: > > # Title > > ## Section 1 > ## Section 2 > > The TOC should contain: > * Section 1 > * Section 2 > (and its corresponding links) > > If the page is: > # Section 1 > # Section 1 > > The TOC should be: > * Section 1 > * Section 2 > > If the page is: > # There is only one title > > foo bar blah blah... > > Then there is not TOC. > > If there any way to do it by changing the template? I didn''t find any > document about how to write templates (something like how to write > condition stmt, loop stmt and how to find available variables etc.) I > would be appreciate if anyone could point me a link or a solution. > > Regards, > -Monnand
Hi, On 2012-05-03 22:18 -0400 monnand wrote:> Hi all, > > I am constructing a website using webgen. By changing > default.template, I could finally insert a TOC in the side bar with > {menu: {used_nodes: fragments}}. Now, I want to do something more > complex: > > Given any page, webgen should decide how to generate the table of > content using the following algorithm: > > - If the number of h1 headings is greater than 1, i.e. > 1. Then use > all h1 headings as TOC > - Else find the number of headings in lower level, until there is a > level of headings in which there are more than 1 headings, use > headings in that level in TOC. > - Else do not generate TOC.There is no such algorithm built into webgen right now. You would have to code this yourself. However, note that fragments are only created for headers that have an ID set. So you could do this with the {menu: {used_nodes: fragments}} tag if you just set the IDs only on those headers that you want to have in the menu.> If there any way to do it by changing the template? I didn''t find any > document about how to write templates (something like how to write > condition stmt, loop stmt and how to find available variables etc.) I > would be appreciate if anyone could point me a link or a solution.Have a look at http://webgen.rubyforge.org/documentation/contentprocessor/erb.html This is the default content processor used in template files for adding Ruby code statements. Best regards, Thomas
Hi Thomas, Thanks for your answer! Thomas Leitner wrote, On 05/22/2012 02:01 AM:> Hi, > > On 2012-05-03 22:18 -0400 monnand wrote: >> Hi all, >> >> I am constructing a website using webgen. By changing >> default.template, I could finally insert a TOC in the side bar with >> {menu: {used_nodes: fragments}}. Now, I want to do something more >> complex: >> >> Given any page, webgen should decide how to generate the table of >> content using the following algorithm: >> >> - If the number of h1 headings is greater than 1, i.e.> 1. Then use >> all h1 headings as TOC >> - Else find the number of headings in lower level, until there is a >> level of headings in which there are more than 1 headings, use >> headings in that level in TOC. >> - Else do not generate TOC. > > There is no such algorithm built into webgen right now. You would have > to code this yourself. However, note that fragments are only created > for headers that have an ID set. > > So you could do this with the {menu: {used_nodes: fragments}} tag if > you just set the IDs only on those headers that you want to have in > the menu.Thanks! That''s all I need. In fact, I have already got a solution by reading webgen''s class document. My previous problem was unable to find the right variable available in template to manipulate the titles. Now I use context.node.children to test if there are more than one children under context.node. I don''t know if this is a right/idiomatic way to do. But it works fine.> >> If there any way to do it by changing the template? I didn''t find any >> document about how to write templates (something like how to write >> condition stmt, loop stmt and how to find available variables etc.) I >> would be appreciate if anyone could point me a link or a solution. > > Have a look at > http://webgen.rubyforge.org/documentation/contentprocessor/erb.html > This is the default content processor used in template files for adding > Ruby code statements.I see. That''s where I found the solution. Thank you very much! -Monnand> > Best regards, > Thomas >