Skip to main content
added 163 characters in body
Source Link
Letharion
  • 27.5k
  • 11
  • 83
  • 141

Edit: I realise after writing the answer that I sound rather negative. Sorry about that, but I can't phrase this in a positive fashion.

Answer: First, and foremost, you are mixing logic, with output. The template should not have logic in it, and should absolutely not care about why it was called.

When a user visits node/1, core will call node_load(1). This is in no way different from calling node_load(1) anywhere else.

A node template does also not execute as a direct result of loading a node. Templates are used when the theme layer renders a node, which is the completely other end of the response.

You can, in theory, call debug_backtrace() to get the call stack, and from there figure out more information about from where node_load was called, but there is almost certainly exactly 0 valid use-cases for this. I guarantee that you do not want to go down that path, and even considering it means that something is seriously wrong.

I have built Drupal-sites professionaly for years now, and have done some really, really ugly hacks during that time. Neither of them would come anywhere near analysing the stacktrace, in the theme layer.

Edit: I realise after writing the answer that I sound rather negative. Sorry about that, but I can't phrase this in a positive fashion.

Answer: When a user visits node/1, core will call node_load(1). This is in no way different from calling node_load(1) anywhere else.

A node template does also not execute as a direct result of loading a node. Templates are used when the theme layer renders a node, which is the completely other end of the response.

You can, in theory, call debug_backtrace() to get the call stack, and from there figure out more information about from where node_load was called, but there is almost certainly exactly 0 valid use-cases for this. I guarantee that you do not want to go down that path, and even considering it means that something is seriously wrong.

I have built Drupal-sites professionaly for years now, and have done some really, really ugly hacks during that time. Neither of them would come anywhere near analysing the stacktrace, in the theme layer.

Edit: I realise after writing the answer that I sound rather negative. Sorry about that, but I can't phrase this in a positive fashion.

Answer: First, and foremost, you are mixing logic, with output. The template should not have logic in it, and should absolutely not care about why it was called.

When a user visits node/1, core will call node_load(1). This is in no way different from calling node_load(1) anywhere else.

A node template does also not execute as a direct result of loading a node. Templates are used when the theme layer renders a node, which is the completely other end of the response.

You can, in theory, call debug_backtrace() to get the call stack, and from there figure out more information about from where node_load was called, but there is almost certainly exactly 0 valid use-cases for this. I guarantee that you do not want to go down that path, and even considering it means that something is seriously wrong.

I have built Drupal-sites professionaly for years now, and have done some really, really ugly hacks during that time. Neither of them would come anywhere near analysing the stacktrace, in the theme layer.

Source Link
Letharion
  • 27.5k
  • 11
  • 83
  • 141

Edit: I realise after writing the answer that I sound rather negative. Sorry about that, but I can't phrase this in a positive fashion.

Answer: When a user visits node/1, core will call node_load(1). This is in no way different from calling node_load(1) anywhere else.

A node template does also not execute as a direct result of loading a node. Templates are used when the theme layer renders a node, which is the completely other end of the response.

You can, in theory, call debug_backtrace() to get the call stack, and from there figure out more information about from where node_load was called, but there is almost certainly exactly 0 valid use-cases for this. I guarantee that you do not want to go down that path, and even considering it means that something is seriously wrong.

I have built Drupal-sites professionaly for years now, and have done some really, really ugly hacks during that time. Neither of them would come anywhere near analysing the stacktrace, in the theme layer.