From: Michael Campbell Date: 2003-12-20T07:11:46+09:00 Subject: Re: Amrita question(s) Ara.T.Howard wrote: >>2 Is there a way to mask out non-data elements if a data-element doesn't >>exist? >>Suppose I have in my html: > >>Name: > >>I don't want "Name:" to show if the :name id doesn't exist. I'm sure >>I'm overlooking something fundamental here, but I've just started so >>not sure where to look. > > simply do not put ':name' into you data structure: > ~/eg/ruby > cat b.rb > > require 'amrita/template'; include Amrita > > t = TemplateText.new 'not included' > > t.expand STDOUT, :foo => 42 This would require that I put my field names (in my example above, "Name:") in the model, which I'd like not to do, since it's not PART of my model, it's part of my markup. Perhaps my example is overloaded too much on terms; let me rephrase. I want the following to display IFF my model contains the data element "element". Field Label: element Now, I can do this like so: code: {:element => "Field Label: element" } html: or something like code: {:elementlabel => "Field Label: ", :element => "element" } html: but neither is very satisfying. I don't like either solution as they put my markup directly into the code (and my model data), and in the second case, requires that I manipulate 2 values for every labelled output. What I'd *LIKE* somehow is to have html: Field Label: and some version of code that omits the "Field Label:" part if :element doesn't exist; I understand the actual value referenced by the :element key already won't show. In other words, "sometag" is just a conditional "is it there or not?" test, where "span" tests for existence AND displays it. I can't use "span" as "sometag" above, since if the value *DOES* exist, the "Field Label:" text will not be used, but rather replaced with said value. Do I need to write my own tag? As for your comment about blocking out big chunks of HTML, how do you do that? If you have sections separated by
...
, how do you make the Amrita parser not replace the HTML code with the value of the :commentoutthischunk value? YOu can't use {:commentoutthischunk => nil}, but any other non-nil value you use will not only eliminate your HTML, but be printed in its place. (Or do you use a space or something innocuous? ) Thanks, Michael __________________________________ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/