-1
  1. Create content for a custom content type "Artist" (Add Content > Artist)

  2. Note the node number (/node/[number]).

  3. Set an URL alias for the node.

node/[number] to /details/[node:field_artist_title]

I want to hide the content from this content type by URL. Any idea how can I remove the content from node__content?

  • 2
    In order to get a decent and helpful answer, you should provide more details than two numbered points and a sentence. (Compare "Be specific" of drupal.stackexchange.com/help/how-to-ask) Please re-edit your question. Describe (in more details), what exactly you want to hide, probably also why you want to hide it, and what you tried so far that did not give the expected results. – Mario Steinitz May 26 '18 at 13:16
  • Cross-posted on stackoverflow.com/q/50540245/2199525 – leymannx May 26 '18 at 14:47
  • 2
    Still anticipating that the entire node shall be hidden. But given the information in the question, it's all nothing else but guessing. – Mario Steinitz May 26 '18 at 23:36
2

You could check either for a path alias fragment or the node ID in a node preprocess function and then unset the whole content like following.

Ensure to replace MYTHEME/MYMODULE with your custom (sub-)theme's or custom module's machine name.

To be placed in either your custom (sub-)theme's template.php file (D7) or MYTHEME.theme file (D8) or in a custom module's MYMODULE.module file (D7 & D8).

/**
 * Implements template_preprocess_node.
 */
function MYTHEME/MYMODULE_preprocess_node(&$variables) {

  // Check for node type.
  if ($variables['node']->getType() == 'artist') {

    $current_path  = \Drupal::service('path.current')->getPath();
    $current_alias = \Drupal::service('path.alias_manager')->getAliasByPath($current_path);
    $alias_args    = explode('/', $current_alias);

    // 1. Unset content per path alias.
    if ((isset($alias_args[0]) && $alias_args[0] == 'details')
      && (isset($alias_args[1]) && $alias_args[1] == 'michael-jackson')) {
      unset($variables['content']);
    }

    // 2. Or unset content by node ID.
    if ($variables['node']->id() == '123') {
      unset($variables['content']);
    }
  }
}

You could also use simple CSS.

#node-123 .field-name-body { display: none; }
| improve this answer | |
  • its showing the null value in the $variables['type'] when i try in node.module under core folder – Manmeet Khurana May 28 '18 at 5:37
  • ,its works for me but you need to update your answer , I have get the node content type name by using $variables['node']->getType() ; Thank you – Manmeet Khurana May 28 '18 at 6:06
  • @ManmeetKhurana – First of all, never ever hack the core or contrib modules. Create a custom module or custom theme to place your code. Else it's simply gonna be deleted automatically on the next update. – leymannx May 28 '18 at 6:31
  • @ManmeetKhurana – Second, right I'll update my answer to reflect the D8 code. And the next time you ask a question, please don't cross-post it on SO and don't tag it with D7 as this is misleading. – leymannx May 28 '18 at 6:32
  • @ManmeetKhurana – And last but not least, arg() is deprecated and will be removed. – leymannx May 28 '18 at 6:42
0

The body of this node has a class as page-node-1520 you can use it in CSS to hide what you want. Or you can create your node twig template page--node--1520.html.twig

| improve this answer | |
  • i have set the pattern for the content type and want to hide for all content for particular content type pattern I have change node/1520 to /works/[node:title] – Manmeet Khurana May 26 '18 at 5:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.