Referencing CCK fields in other mods?
yountod - October 13, 2009 - 15:47
I'd like to create a custom CCK field called "Ad_Slot" and put a Google AdSense slot ID in there.
Then, in other mods (in this case it would be "AdSense Injection") I'd like to reference the value of that field. (In this particular example I'm trying to change Slot ID's dynamically per-node.)
I see things like "%body" and such in that mod's text boxes, but I'm not sure I can just create a "field_adslot" and then use "%adslot" or "field_adslot" or "field_adslot["value"]" or something like this.
Will I have to dive into source files to create "node->field_adslot" references or something? Or is this what a "token" is?
Apologies, I'm not even sure what notion to search for here...

_
You can't create a cck field apart from a node so I'm not entirely sure what you're asking for. If you just need to store this value somewhere, you can do it in the variables table and access it with http://api.drupal.org/api/function/variable_set and http://api.drupal.org/api/function/variable_get or make a php global variable for it.
_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.
No, it would be a value
No, it would be a value called up on each individual node of a given content type, not a universal variable. I would be creating the Ad_Slot CCK field in a "story" content type, then I would put a different slot ID# in that field based on who submitted that node.
I'd like the ad injector to use that ID when injecting ads into individual nodes so that each author's stories would be tracked in AdSense by a different slot or channel.
Does this already exist, or can it be done elegantly? I think it would be a powerful Drupal capability. It's a different take on some obsolete revenue-sharing stuff I've been sniffing around here.
_
ah ok... did you try the http://drupal.org/project/computed_field module?
_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.
Oh man, that is cool. I can
Oh man, that is cool. I can automatically populate the slot ID based on the authoring user. Very nice.
Once that's done though, I'm in the same boat - how do I reference that field in the AdSense Injector in a "%body" type of way?
The admin screen has a text box called "Node body ad insertion template" which has the following code:
<div style="float: right; margin: 0; padding: 0 1em .25em 0;">[adsense:250x250:xxxxxxxxxx]</div>%body<br class="clear"/>[adsense:728x90:yyyyyyyyyy]I'd like two computed fields to be entered in place of the two strings (x's and y's above) which are these computed fields, but I don't know the syntax. The help sentence under the code references "filter tags" but I can't find any reference on these. It says:
Ad insertion template. Substitution variables: %body = full node body text. Insert adsense module filter tags. See the adsense.module settings page for a list of supported formats and help with filter tags.
_
It's pretty simple actually-- you can reference any field on any node by doing something like:
<?php$nid = 1;
$node = node_load($nid);
print $node->field_fieldname[0]['value'];
?>
_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.
I got it, fan fudgin' TASTIC!
I used your tips but did it differently, because the php code wouldn't execute when placed in the Injector dialogue.
For the community at large (don't wanna be a help vampire!) I created two CCK fields for ad sense slot ID#'s - the 250px and 728px managed ads - then I hacked the mod a little bit and did two additional replaces to stick those values into the dynamic template right there in the code. It is sweet. I can now track revenue generated PER AUTHOR by different channels in AdSense. Wow.
THANKS for your support!
_
EXCELLENT-- and thanks for posting your solution back!
_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.