1
{% if logged_in == false %} 
 <div id="promoiton">
  <div id="promotion-image">
   <div id="promotion-bg">
   <div id="promotion-text">
   <h2>Heading</h2>
   <p>some text.</p>
  <ul>
     <li>something here</li>

   </ul>
    <button<a class="btn btn-primary btn-lg" href="#" role="button">Learn
    more</a></button>
   </div>
  </div>
 </div>
</div>
{% else %}

 <iframe{{ attributes }}{% if url is not empty %} src="{{ url }}{% if 
 query is not empty %}?{{ query | url_encode }}{% endif %}"{% endif %}>    
 </iframe>
 {% endif %}

Hi Folks, in the code example above I have tried do doing some twig foo. It works greate if th user is looged out.

But what if I like to seperate contnet types by machine name?

So for example you have two names lets say article and block

How to make shure that the field is visible on block but not on artivle for logged out users? in short what is the required functioon to get false or true bi a string containing the content type machine name to do something like

 {% if logged_in == false || somefunction= 'content_type_machine_name' %}

Is that possible?

0

You can set a variable in hook_preprocess_Hook function which has the content type and then use that variable in twig file. $node = \Drupal::routeMatch()->getParameter('node'); $nids = $node->nid->value; if($nids){ $variables['content_type'] = $node->bundle(); }

| improve this answer | |
  • thats $node='content_type' in the if statement? – Josh Dec 10 '16 at 10:37
  • {% if content_type == "etc" %} – Deepak modi Dec 10 '16 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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