Lua syntax for tags

Found a bug? Just having trouble getting Trunk to do what you want? Want to help other users?

Lua syntax for tags

Postby Merkuri » Sat Jun 02, 2012 1:41 am

I'm new to lua scripting, but not scripting in general, and I can't seem to figure out how to read what tags are on a page. I want to make a script to show certain content based on the tags that page has. I plan to use this in the header and footer, so I can just tag a page to automatically add a certain header and footer.

Are there any examples I can look at? I wish there were more examples of how to use lua to get specific information about a page.
Merkuri
 
Posts: 12
Joined: Sat Jun 02, 2012 1:14 am

Re: Lua syntax for tags

Postby mgkennard » Tue Jun 05, 2012 3:36 pm

The best way would be to define a function which can check for the existent of an item in a list.

For example:

Code: Select all
function Set (list)
  local set = {}
  for _, l in ipairs(list) do set[l] = true end
  return set
end

if Set(page.tags)["Tag I am looking for"] then
    return "This page has the tag I am looking for"
end


Lua is a great language but does lack some of the built in functions you would find in languages such as Python.

Matthew
Apps On The Move
mgkennard
Site Admin
 
Posts: 758
Joined: Mon Jul 21, 2008 2:40 pm

Re: Lua syntax for tags

Postby Merkuri » Fri Jun 08, 2012 1:14 am

That works great, thanks!
Merkuri
 
Posts: 12
Joined: Sat Jun 02, 2012 1:14 am


Return to Problems

Who is online

Users browsing this forum: No registered users and 1 guest