Topic on Extension talk:Capiunto

Simple way to use conditional :addRow commands in Module?

2
Flyingratchet (talkcontribs)

I'm sure I'm missing something but after much reading of documentation and Googling I can't figure out how to have conditional control of the Capiunto :addRow command. First and foremost I'm just trying to say that if there is no information provided by the template call then don't add the row to the infobox.


I found the following code from here

if args.myArgs then retval:addRow('My Args', args.myArgs) end

that seems to be for this purpose but when I add a line like this among other just regular :addRow lines—I get an error "unexpected symbol ":" near "addRow". I'm sure I'm just doing something boneheaded but can't figure it out. Here is the full code in my module.


local capiunto = require 'capiunto'

local p = {}

function p.main(frame)

local args = frame:getParent().args

local headerStyle

if args.headerstyle and args.headerstyle ~= '' then

headerStyle = string.format('background-color:%s;', args.headerstyle)

else

headerStyle = 'background-color:#bae4bc;'

end

local retval = capiunto.create( {

Title = args.Title,

headerStyle = headerStyle,

} )

    :addRow( 'Type', args.Type)

    if args.myArgs then retval:addRow('My Args', args.myArgs) end

    :addRow( 'Focus', args.Focus )

:addRow( 'Focus_keywords', args.Focus_keywords )

:addRow( 'Geographic purview', args.Geographic_purview )

    :addRow( 'Website', args.Website )

return retval

end

return p

Flyingratchet (talkcontribs)

I figured out my own question finally—just a problem with my ignorance of syntax. The Capiunto ":addRow" commands that are inside control loops need to be explicitly prefaced by the name of the local variable, in this case "retval", so "retval:addRow" not ":addRow". The latter version works when the commands are outside the control loops.

Reply to "Simple way to use conditional :addRow commands in Module?"