Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I am trying to use the new custom field area and I must say it is very useful. Pardon my ignorance, following question may be weird but:
If I try to use something like print $date.... as in your example video, it is ok. But can I use an array that is defined in my theme's template.php file? When I try something like $terms, it displays nothing. For example:
<div class="taxonomy"><?php print $terms; ?></div>
doesn't work in that area, but if I write it in node.tpl.php, it works...
Thanks,
Sinan
Comments
Comment #1
swentel CreditAttribution: swentel commentedThe only thing thats available in a custom field is the complete $node object. So things like $terms aren't available there. Now, for terms, you can normally use the taxonomy field which should be available by default in the module - although there is an issue in the queue (from beta 1) that taxonomy doesn't show up - should retest that.
I really need to update the documentation fast enough. You could use something like this though in a custom field:
However, this is executing the same code twice (it's already done in template_preprocess_node and should be available as field)
Comment #2
Sinan Erdem CreditAttribution: Sinan Erdem commentedThank you for the quick answer.
I tried and separated the vocabularies with a pre-process function in my template.php file. I used the approach in this article: http://11heavens.com/putting-some-order-in-your-terms
Now, I can use the newly created arrays of variables ($tags, $categories, etc.) in my node.tpl.php file. But not in the custom field. Is it possible to use it somehow?
I am sorry if I am bothering you with this specific issue of my own.
Thanks again for your answer...
Sinan
Comment #3
swentel CreditAttribution: swentel commentedNo problem, we like questions as it makes us understand we make mistakes too :) We identified the problem. We also implement template_preprocess_node in our code, the original $terms variable is moved in our code to $node->content['terms'] .. This works fine as long as there is no template_preprocess_node in template.php because that function runs after our code. So in fact, you found a racing condition problem here. We'll need to rethink the way we deal with variables.
In the meantime, you could use that same code in the custom field, with a few small changes (I applied them already):
Not so elegant of course, but it should work :)
I reopened the issue and changed the title to reflect the problem, thanks for the report!
Comment #4
Sinan Erdem CreditAttribution: Sinan Erdem commentedYou are fantastic! Thank you for the effort.
[wrong comment deleted by me here not to confuse anybody]
With this fantastic module and generous help, you are making us lazy :)
Cheers,
Sinan
Comment #5
Sinan Erdem CreditAttribution: Sinan Erdem commented[wrong comment deleted by me]
I will wait for the next release of the module.
Thanks again..
Comment #6
Sinan Erdem CreditAttribution: Sinan Erdem commentedCompletely ignore my last 3 entries (including this one). It is late and I started to think like a cucumber :)
Comment #7
swentel CreditAttribution: swentel commented@etcetera9 no worries :) There will be a bit more chatter on this thread by other people also because we're going to brainstorm on how to tackle this problem.
Ok, for the other guys (stalksi, zuuperman, jyve), what are we going to todo here ? We need our preprocess stuff because we need to render data in regions. Currently I see 2 options:
1) Do nothing and tell people, sorry about that. If you want to overcome this problem, well don't implement such stuff and write a lot of documentation on howto make work arounds for it (ie, custom fields UI and custom PHP code). Sounds a bit arrogant, does it ? :)
2) Move the code of our preprocess to a complete separate function. We keep our preprocess_node function which calls this helper function with an extra check however. This check will include some intelligent code (tbd) which detects if people included this a call to this helper function at the bottom in one of the other preprocess_hook functions (engineName_engine_preprocess_hook, engineName_preprocess_hook or themeName_preprocess_hook). This way, we can still keep the code module-centric (and switching themes has no effect) but can be overridable. I'd go for this option.
Thoughts ?
Comment #8
swentel CreditAttribution: swentel commentedOk, went for solution number 2, see http://drupal.org/node/572614 for documentation.
Comment #10
everest19 CreditAttribution: everest19 commentedHi!
How can you have a node and web links displat like newsvine?