Jump to content

Tables 101


Recommended Posts

I'm trying to create a table to use with a flat file.

 

Instance File = TableMarkup1.txt

Resource Name = TableMarkup1

 

<table columns="1">

<column width=24984>

<row>

<cell>

<variable name="Dinner01Title"> <variable name="Dinner01Price">

<row>

<cell>

<variable name="Dinner01Body">

<row>

<cell>

<variable name="Dinner02Title"> <variable name="Dinner02Price">

<row>

<cell>

<variable name="Dinner02Body">

</table>

 

Page 36 of Tags Reference refers to "Make a Rule with the Input Options from the Data Definition wizard..."

 

I tried to make a rule that simply returns the resource - this is invalid

-------------

return

Resource("TableMarkup1")

Link to comment
Share on other sites

You need to add a resource of type "Tagged File" which points to the text file containing the table markup.

 

Although I would consider generating the table markup in a rule - something like this:

var table = '<table columns="1"><column width=24984>\n';
var numItems = 2; // however many you have; this can be calculated as well
for (var i = 1; i <= numItems; i++)
{
 table += '<row><cell><variable name="Dinner' +
     FormatNumber("00", i) + 'Title"> <variable name="Dinner' +
     FormatNumber("00", i) + 'Price">\n';
}
return table;

Link to comment
Share on other sites

Dan,

 

I had the tagged file added, I had failed at making a working rule to access it. Your code led me to the answer. I had "Return" on a separate line from "Resource("TableMarkup1")". I have the rule working now.

 

Now the question is formatting. Can I embed the formatting in the tagged markup? Can I use rules instead of field names in the tagged markup?

 

As for doing it all in a rule, I'm at a loss as to how I would adapt your sample code to the project. There will be over 100 items, each using from 1 to 4 fields, not all having the "Dinner" prefix.

 

Andy

Link to comment
Share on other sites

Dan,

 

Ssome progress, working from your code sample, since my last note. Now I'm having an issue trying to add a new line within the cell. The way I've done it does not put Dinner01Body on a new line. See attached DanRulePlus.txt

 

I also need to do both cell and type formatting based on the test. The rule that I was using before is attached as BasicTestRule.txt

 

Any further help that you can provide would be greatly appreciated.

 

Andy

DanRulePlus.txt

BasicTestRule.txt

Link to comment
Share on other sites

Now the question is formatting. Can I embed the formatting in the tagged markup? Can I use rules instead of field names in the tagged markup?

Yes to both. The <variable> tag will pick up rules as well as fields. Or you could call the Rule function in your code.

As for doing it all in a rule, I'm at a loss as to how I would adapt your sample code to the project. There will be over 100 items, each using from 1 to 4 fields, not all having the "Dinner" prefix.

Well, this is kind of going beyond "Tables 101" and turning into a a custom template-building (consulting) type question, but basically, you can output whatever you want. I'd have to see the data to offer more specific suggestions.

Link to comment
Share on other sites

Ssome progress, working from your code sample, since my last note. Now I'm having an issue trying to add a new line within the cell. The way I've done it does not put Dinner01Body on a new line. See attached DanRulePlus.txt

You need to use a <br> tag to output a new line. The newline character "\n" in the rule is simply to aid in validating the result in the Rule Editor, and is ignored by the tagged markup parser at composition time.

I also need to do both cell and type formatting based on the test. The rule that I was using before is attached as BasicTestRule.txt

You can combine the logic several ways. I would do something like this:

var table = '<table columns="1"><column width=24984>\n';
var numItems = 8; // the maximum number
for (var i = 1; i <= numItems; i++)
{
   var num = FormatNumber("00", i);
   if (!Field("Dinner" + num + "Title"))
       continue; // skip empty fields

   var TitleAndPrice = Field("Dinner" + num + "Title") + ' ' +
                       Field("Dinner" + num + "Price");

   if (Field("Dinner" + num + "Special") == "y")
       TitleAndPrice = "<color name=7511>" + TitleAndPrice + "</color>";

   table += '<row><cell>' + TitleAndPrice + '<br>' +
               Field("Dinner" + num + "Body") + "\n";
}
return table;

P.S. Please feel free to include the code directly in your posts, using the "#" button on the "Go Advanced" view to wrap it in a code block (as in my example directly above), instead of posting attachments.

Link to comment
Share on other sites

Thanks for taking this on into Tables 202. I will work with this and hopefully get this project off the ground.

Great!

In the meantime, is there any good place to get a fish taco in your town?

I wish there were! I have to wait for my next trip to San Diego. :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...