problem with building table in a frame

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
Holladerwaldelf
Cave Troll
Posts: 74
Joined: Fri Aug 07, 2015 1:16 pm

problem with building table in a frame

Post by Holladerwaldelf »

I am trying to build a frame that has a few tables under each other, each table has a certain number of rows. So here is what I did and it worked fine:
Spoiler

Code: Select all

[h: formHandlerLink = macroLinkText('csheet.handler@lib:token','all')]	

[h: header.array = json.append("[]","HEAD1","HEAD2","HEAD3")]
[h: row.array = json.append("[]","row1","row2","row3")]

[frame("TEST"): 
	{<html>

    <head>
		<link rel="stylesheet" type="text/css" href="css@lib:token"></link>
    </head>

    <body>
		<form action='[r:formHandlerLink]' method='json'>
			
		[r, foreach(header,header.array,""), code:
			{
			<table>
			<th>[r:header]</th>
			[r, foreach(row,row.array,""): strformat("<tr>%{row}</tr>")]
			</table>
			}]
				
		</form>
    </body>

    </html>}
]	
But when I change the inner foreach-loop like this I get an "error in body of roll" (not saying what the error actually is):
Spoiler

Code: Select all

[h: formHandlerLink = macroLinkText('csheet.handler@lib:token','all')]	

[h: header.array = json.append("[]","HEAD1","HEAD2","HEAD3")]
[h: row.array = json.append("[]","row1","row2","row3")]

[frame("TEST"): 
	{<html>

    <head>
		<link rel="stylesheet" type="text/css" href="css@lib:token"></link>
    </head>

    <body>
		<form action='[r:formHandlerLink]' method='json'>
			
		[r, foreach(header,header.array,""), code:
			{
			<table>
			<th>[r:header]</th>
			[r, foreach(row,row.array,""), code: 
				{
				[strformat("<tr>%{row}</tr>")]
				}]
			</table>
			}]
				
		</form>
    </body>

    </html>}
]	
The problem is that I would really like to have the "code"-option in the inner foreach-loop as the "row"-variable is supposed to be an object and I want to show the values of the different keys of the object in each row.

Any help would be greatly appreciated.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: problem with building table in a frame

Post by wolph42 »

too many code levels (read the article linked in sig).

This should solve it:

Code: Select all

[h: formHandlerLink = macroLinkText('csheet.handler@lib:token','all')]     

[h: header.array = json.append("[]","HEAD1","HEAD2","HEAD3")]
[h: row.array = json.append("[]","row1","row2","row3")]

[frame("TEST"): 
    {<html>

    <head>
        <link rel="stylesheet" type="text/css" href="css@lib:token"></link>
    </head>

    <body>
        <form action='[r:formHandlerLink]' method='json'>
         
        [r, foreach(header,header.array,""), code:
        {
            <table>
            <th>[r:header]</th>
            [r, foreach(row,row.array,""): strformat("<tr>%{row}</tr>")]
            </table>
        }]
            
        </form>
    </body>

    </html>}
]      

Holladerwaldelf
Cave Troll
Posts: 74
Joined: Fri Aug 07, 2015 1:16 pm

Re: problem with building table in a frame

Post by Holladerwaldelf »

Oh yeah, the code levels. I overlooked that "frame" creates another {}... :oops:
Thanks!

Post Reply

Return to “Macros”