Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Dereferencing a column name to it's value

Quote Reply
Dereferencing a column name to it's value
I know it's late and I might be tired, but...

I am trying to set a variable equal to the value of a column name.

col_name comes from a plugin option and is the name of a column. i.e. Color.
Code:
<%set value =col_name%>
<%value%>
Displays 'Color'

I want the value from that column, i.e. 'Red'

I did consult the template docs, but didn't find the solution there Unsure
I also tried other variations, but no go.

Thanks,
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] Dereferencing a column name to it's value In reply to
try "$col_name"

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Dereferencing a column name to it's value In reply to
Nope.

I've tried:
----------------------------------
<%set value = $col_name%>
<%value%> Displays 'Color' ( I want the column's value, ie 'Red')
----------------------------------
<%set value = "$col_name"%>
<%value%> Displays 'Color' ( I want the column's value, ie 'Red')
----------------------------------
<%set value = '$col_name'%>
<%value%> Displays '$col_name'
----------------------------------
<%set value = "$$col_name"%>
<%value%> Displays '$col_name'


Let me try to clarify.
I have a plugin config option which holds the name of a column (ie 'Color' is the name of a Links column)
I want to display the value from the column 'Color'.
If use the tag <%Color%> this works fine EXCEPT that
I do not know the name of the column (The column name is a plugin setup option).

So, I have loaded the config options at the top of the template with:
<%Links::Plugins::get_plugin_user_cfg('MyPlugin')%>
The plugin option is named 'col_name'.

So I am trying to get the value of 'col_name' column.

Sorry, It is a hard question to ask. I need to double derefference to get to the value?

Thanks again,
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] Dereferencing a column name to it's value In reply to
I think I understand. The user puts in the name of a column from their Links table. You want to get the value for that column loaded into your plugin configuration.

How about something like:

Code:
sub plugin_config {
my $id = shift;
my $rec = $DB->table("Links")->get($id);
my $cfg = Links::Plugins::get_plugin_user_cfg("MyPlugin");
$cfg->{col_name} = $rec->{$cfg->{col_name}};

return { PLG_CFG => $cfg };
}

Then in your template, instead of:

Code:
<%Links::Plugins::get_plugin_user_cfg('MyPlugin')%>

do:

Code:
<%Plugins::MyPlugin::plugin_config($ID)%>

then to access the value, use:

Code:
<%PLG_CFG.col_name%>

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Dereferencing a column name to it's value In reply to
hmmm, seems like a lot of work when I can already use a tag to display the column's data.

Quote:
The user puts in the name of a column from their Links table.

Yes, but it happens when the plugin gets installed. They choose a column, and I save the name.

Quote:
You want to get the value for that column loaded into your plugin configuration.

Not quite. The value (column name) is already in the config. I just want to display the value from the column.

I understand your sub plugin_config() example, and although that would work, it seems as though
I shouldn't need to call another routine to get something I think I already have. Unsure

One more try, if I don't get it, I'll just return another tag from the plugin.

So, during install user picks a column named 'Color'
I save this to config as col_name. So col_name => Color.
I have loaded the config at the top of the template.

If I use the tag <%col_name%>, it displays 'Color'.
If I use the tag <%Color%>, it displays 'Red'.

Both of those are correct, but I can't arbitrarily use the tag <%Color%>, because the column
could be named 'Colour'.

Can I take the text value for col_name (which is 'Color', and is also a Link column name)
and get it's value without using another subroutine to grab the value from the link column?

Thanks for sticking with me on this. Limecat would be pleased Sly. I am.

Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com

Last edited by:

rgbworld: Jul 31, 2006, 12:40 PM
Quote Reply
Re: [rgbworld] Dereferencing a column name to it's value In reply to
Okay, looking at the GT::Template tutorial, it appears you can include tags inside tags. This is assuming the tags for the record being displayed are in hash format... (I normally use an array, with each element being a hash with a single key, "rec", who's value is a reference to a hash)

You can do:

Code:
<%set col_name = ${plugin_cfg.col_name}%>
<%rec.$col_name%>

Look at the documentation, about 3/4ths the way down the page.

Philip
------------------
Limecat is not pleased.

Last edited by:

fuzzy logic: Jul 31, 2006, 8:50 PM
Quote Reply
Re: [fuzzy logic] Dereferencing a column name to it's value In reply to
Ok, I give. It simply doesn't work, no matter what I've tried.

I'll find another way to skin the... (oops)

I'll use some other method. Unimpressed

Thanks though. Nobody's fault but mine.

Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com