By aryanto on
Hello everybody,
I would like to achieve the following
function my_module_main() {
// set variable page_is_teaser based on the $teaser variable of the node
If (page_is_teaser) {
// Do this
} else {
// Do that
}
}I have been searching for information for 4 days with no luck. Most of the information I found seem to suggest to use hook_nodeapi to grab the $teaser variable. But I can not figure out how to use it.
As you can guess, I am quite new to this. So could anybody give me some hints?
Comments
Here's an example of using
Here's an example of using hook_view() : http://api.drupal.org/api/function/hook_view/6
hope this points you in the right direction.
cheers
-----------------------------------------
http://www.netrift.com - Custom modules
http://ulisting.netriftsolutions.com - Drupal Real Estate Module for Drupal 6
http://drupal.org/project/friend - Social Neworking for Drupal 6
Thanks but it does not set the variable I need
Thanks Ken,
But that does not set the $page_is_teaser boolean variable in my_module_main().
I seemed to find the back door by using the $GLOBALS variable, but I have not tried. I heard setting the variable like that is not an elegant solution.
I think I have to change my example above to avoid confusion. I hope the example below is more clear.
Cheers,
Anto
This is a bit confusing ...
This is a bit confusing ... the teaser var will depend on what you're trying to do and when.
You function above won't work because your $pag_is_teaser is in the wrong scope. You'll need to pass it into the function .
?>
-----------------------------------------
http://www.netrift.com - Custom modules
http://ulisting.netriftsolutions.com - Drupal Real Estate Module for Drupal 6
http://drupal.org/project/friend - Social Neworking for Drupal 6
What I actually would to achieve
OK. I probably wrongly explain this. So let me tell you what I actually would like to achieve.
I would like to resize an image based on whether the node is a teaser or body node. As I can not directly use the $teaser variable like in page.tpl.php, I thought I have to grab that first and store it in another variable within my module, which in this case is $page_is_teaser. Then use that $page_is_teaser variable to switch the image size.
HI , You should probably
HI ,
You should probably use the hook_view() which I gave an example of. That hook will be called everytime a node is view.
http://api.drupal.org/api/function/hook_view/6
cheers
-----------------------------------------
http://www.netrift.com - Custom modules
http://ulisting.netriftsolutions.com - Drupal Real Estate Module for Drupal 6
http://drupal.org/project/friend - Social Neworking for Drupal 6
Thanks, but I don't think that would work
I am still quite new in the development of module, but I don't think using hook_view would work. According to the link you gave us, hook_view should set the $teaser variable. So we can not use $teaser variable for process selection inside hook_view.
After trying out a lot of things, I think I can not actually even use the $teaser variable for process selection at all. As what I want to achieve is modifying a string just before it is being passed into the hook_filter (I think). So it will be too late if I modified the string after the $teaser variable being set. I am not entirely sure about this as I still don't know the process flow in Drupal. If somebody could point me a documentation about process flow in Drupal, I would really appreciate that.
It seems to work when I modify the string which is inside $node->teaser at hook_noapi with 'op'='load', but it screws up other thing. I guess that is not a good way to do alteration. So I guess I can not modify that string.
I think my option now is to modify the parameters on img tag at 'op'='alter' or 'op'='view' of hook_nodeapi. Lets see how it goes.
Problem was actually solved
I just would like to let you know that I have actually managed to solve this issue using hook_nodeapi with op=alter. It took me quite a while to understand how hook_nodeapi works. Even it needs longer codes, I think it is the safest solution as it does not break some other parts.
For those who are interested to see the result, you can have a look here. And if you would like to know the story of building my website, you can read that here.