Hello, I am trying to use global variables, as pointed out at webgen FAQ page, but no success. I am trying to put the following lines at config.yaml file: Core/Configuration: customVars: {myVar: This is really nice!} I always get the error message:> An error has occurred: > Configuration invalid: No such configuration option: customVarsWhat am I missing here? Is there another way to define global values (numbers, strings etc.) and use them in lots of pages? Thx for your attention.
On Fri, 5 Mar 2010 15:15:31 -0800 (PST), Paulo Almeida wrote:> Hello, > > I am trying to use global variables, as pointed out at webgen FAQ > page, but no success. I am trying to put the following lines at > config.yaml file: > > Core/Configuration: > customVars: > {myVar: This is really nice!} > > I always get the error message: > > > An error has occurred: > > Configuration invalid: No such configuration option: customVars > > What am I missing here?Which version of webgen are you using? From the example above, it seems that you are using webgen 0.4.x (and therefore the FAQ from http://webgen.rubyforge.org/documentation/0.4.x/documentation/howto.html). Note that there is an error in your example above: You need to indent customVars with two spaces: Core/Configuration: customVars: myVar: This is really nice The above should work. Best regards, Thomas
Hi Thomas, Thx for your response. I think I mixed up something here. Actually, I am using version 0.5.11 and used FAQ from version 0.4, sorry for my mistake. Anyway, is there a way to create global variables or a similar resource in version 0.5? My problem is: I have some values (integers and strings) which may eventually change with time, such that each time I recompile my website (using ''webgen'' command) they could be grabbed from global variables (or maybe from a data file) to be translated to html format. So every time they change, I can update just one place (config.yaml ou any other data file) and they will be changed in every page that uses them. Regards, Paulo On 6 mar, 05:21, Thomas Leitner <t_leit... at gmx.at> wrote:> On Fri, 5 Mar 2010 15:15:31 -0800 (PST), Paulo Almeida wrote: > > Hello, > > > I am trying to use global variables, as pointed out at webgen FAQ > > page, but no success. I am trying ?to put the following lines at > > config.yaml file: > > > Core/Configuration: > > customVars: > > ? {myVar: This is really nice!} > > > I always get the error message: > > > > An error has occurred: > > > Configuration invalid: No such configuration option: customVars > > > What am I missing here? > > Which version of webgen are you using? From the example above, it seems > that you are using webgen 0.4.x (and therefore the FAQ fromhttp://webgen.rubyforge.org/documentation/0.4.x/documentation/howto.html). > Note that there is an error in your example above: You need to indent > customVars with two spaces: > > Core/Configuration: > ? customVars: > ? ? myVar: This is really nice > > The above should work. > > Best regards, > ? Thomas > _______________________________________________ > webgen-users mailing list > webgen-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/webgen-users
> Thx for your response. I think I mixed up something here. Actually, > I am using version 0.5.11 and used FAQ from version 0.4, sorry for my > mistake. Anyway, is there a way to create global variables or a > similar resource in version 0.5? > > My problem is: I have some values (integers and strings) which may > eventually change with time, such that each time I recompile my > website (using ''webgen'' command) they could be grabbed from global > variables (or maybe from a data file) to be translated to html format. > So every time they change, I can update just one place (config.yaml ou > any other data file) and they will be changed in every page that uses > them.There is no support for such global variables in 0.5.x as there was in 0.4.x. However, you have two possibilities: 1. Define the variables in ext/init.rb by storing them in a new configuration option: Webgen.website_access.config.globals({''mykey'' => ''value'', ''otherkey'' => 5}) Then you can access the values using the following ERB fragment in a page or template file: <%= context.website.config[''globals''][''mykey''] %> 2. Create a meta information file for storing each global variable on each page file that uses it: --- name:alcn **/*.html: mykey: value otherkey: 5 Then you can access the "global variables" in each such page file by using the meta tag: {mykey:} is something as well as {otherkey:} The second variant has the advantage that the page files are automatically regenerated when the values change. And the usage is similar to the one in 0.4.x. So I would try the second variant first! -- Thomas
Thank you again, Thomas! The first suggestion you gave me is working but, as a matter of fact, I observed that everytime I changed the values inside init.rb, I had to manually "touch" the .page files in order to force their recompilation by webgen, as you mentioned. Just for the records, I had to replace the expression Webgen.website_access.config.globals({...}) by Webgen::WebsiteAccess.website.config.globals({...}) to make it work. I put the second and preferred suggestion to work with no issues. Everytime that I change values inside "metainfo" file, webgen automagically recompiles all HTML files and updates those variables inside the rendered page, as wished. Best regards and congrats for your good work. Paulo On 9 mar, 03:42, Thomas Leitner <t_leit... at gmx.at> wrote:> > Thx for your response. I think I mixed up something here. Actually, > > I am using version 0.5.11 and used FAQ from version 0.4, sorry for my > > mistake. Anyway, is there a way to create global variables or a > > similar resource in version 0.5? > > > ? My problem is: I have some values (integers and strings) ?which may > > eventually change with time, such that each time I recompile my > > website (using ''webgen'' command) they could be grabbed from global > > variables (or maybe from a data file) to be translated to html format. > > So every time they change, I can update just one place (config.yaml ou > > any other data file) and they will be changed in every page that uses > > them. > > There is no support for such global variables in 0.5.x as there was in > 0.4.x. However, you have two possibilities: > > 1. Define the variables in ext/init.rb by storing them in a new > ? ?configuration option: > > ? ?Webgen.website_access.config.globals({''mykey'' => ''value'', ''otherkey'' => 5}) > > ? ?Then you can access the values using the following ERB fragment in a > ? ?page or template file: > > ? ?<%= context.website.config[''globals''][''mykey''] %> > > 2. Create a meta information file for storing each global variable on > ? ?each page file that uses it: > > ? ?--- name:alcn > ? ?**/*.html: > ? ? ?mykey: value > ? ? ?otherkey: 5 > > ? ?Then you can access the "global variables" in each such page file by > ? ?using the meta tag: > > ? ?{mykey:} is something as well as {otherkey:} > > The second variant has the advantage that the page files are > automatically regenerated when the values change. And the usage is > similar to the one in 0.4.x. So I would try the second variant first! > > -- Thomas > _______________________________________________ > webgen-users mailing list > webgen-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/webgen-users