Jump to:
| Project: | Panels |
| Version: | 6.x-3.5 |
| Component: | Panel pages |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (duplicate) |
Issue Summary
From the project description page:
Want to display nodes differently based on how a custom CCK field you've added to a node type is set? That is very simple to write and you can use this to change the presentation entirely.
I've searched issues in the forums, but I haven't found a clear, beginner-PHP-level explanation of how to do this. Here's what I have:
A CCK integer field, selected as an on/off checkbox that is supposed to control whether a couple panes are visible. The field is "field_preferences_topblocks" and the values (key|label) are 0|off, 1|on. After some searching, here's the code I came up with for my PHP code in a selection rule:
$node->field_preferences_topblocks[0]['value']; // get the value
$result = $node->field_preferences_topblocks[0]['value'];
return $result == 1; // 1 is my "on" valueWhat I want this to do is select for only those nodes that have the field as "1" or on. Of course, it doesn't work, and I'm not sure how to make it work. If I have to load the node somehow I should also note that I'm using pathauto, so the nodeid is not in the URL.
Thanks for any help.
Comments
#1
Recently I've been looking at ways to get CCK fields (from the node being viewed) as context, but I'm still stuck on that one, too.
#2
I've got a panel variant created where I want the selection rule to be based upon the node content type (simple) and a specific selection of a CCK option field (not as simple). Any guidance on how to use that option field would be awesome. Thanks.
#3
It looks like they're close to a ctools plugin for this at http://drupal.org/node/798180. In that same thread, an alternative using PHP is included.
<?php// Check if CCK field "Section display" has value "Grid"
// CCK field info is in the $contexts variable
$return = FALSE;
if( isset($contexts['argument_nid_1']->data->field_section_display[0]['value']) ){
if( $contexts['argument_nid_1']->data->field_section_display[0]['value'] == 'Grid' ){
$return = TRUE;
}
}
return $return;
?>
Seems like this should work for at least my needs (changing, of course, the CCK field name).
#4
That's enough for me to mark this as a dup and direct people to the CCK issue!
#5
I have visited some drupal.org nodes, including node/798180 before reaching this:
<?php
$retorno = FALSE;
$tabela = db_query("
SELECT field_quadrado_grande_value
FROM content_type_noticia
WHERE field_chamada_value = 'QG'
ORDER BY vid DESC LIMIT 1
");
while ($l = db_fetch_array($tabela)) {
$linha[] = $l;
}
$valor = ($linha[0][field_quadrado_grande_value]);
if ($valor == "QGI"){
$retorno = TRUE;
}
return $retorno;
?>
Querying directly the db you don't have to use $contexts. Using the above code as a visibility rule on the content of my panel I handle two types of layouts depending on the value of field_quadrado_grande_value .
Note that in this case, the view called by the panel is going to be spelled out if and only if the last post of the kind QG has the value QGI on the field_quadrado_grande_value.
After starting by this, It would be a good practice to include the timestamp of the node by complementary querying [node][changed].