We have to get the current node's view_mode
from within the mymodule_preprocess_page(&$variables)
hook. When we tried the following we could not get the view_mode
after performing some validation to make sure we have a node
object.
In the Basic page
, we have a Related Articles
section that is an entity reference to the Article
content type. This returns multiple nodes depending upon the page and we want to ensure the template_preprocess_node()
hook is ran only once.
How can we get the current node's view_mode
from within the template_preprocess_page(&$variables)
hook?
Here is what we tried to do
function mymodule_preprocess_page(&$variables) {
$node = $variables['node'];
if(isset($node) && is_object($node) {
// Tried printing variables but cannot find `view_mode`
ksm($node);
}
}
entity reference
to thebasic page
so we just want to be sure the hook is only run once.