CMS Development

matttunney
Top Contributor

content type variables/tags

Hi,

 

Are there variables set to test which content type is being used.

I'd like to be able to conditionally display a menu in a page header module if the current content type is any part of the blog (listing, content, topic, author).

 

If these varibles are availble, are they documented anywhere?

 

Thanks

 

0 Upvotes
4 Replies 4
Jsum
Key Advisor

content type variables/tags

@matttunney,

 

You can also use HubL. wrap the menu in a condition that checks for your blogs path in the url:

{% if '/blog/' in request.path %}
{{ html }}
{% endif %}

or inversely:

{% unless '/blog/' in request.path %}
{{ html }}
{% unless %}

If your menu is in a custom module in then just replace '{{ hmtl }}' with your menu markup on the custom module. If your menu is a module in a drag-and-drop template then if you are in the old design manager you can click the gear icon and edit css to find the custom wrapper area or just click the module in the new design manager and you can scroll down to find the custom wrapper area on the left side of the screen. You can literally paste the above there and just change 'blog' to whatever your blog's url path is. 

 

The benefit is that all hubl is processed on the server side so the markup for your menu will simply not exist in the document if the condition evaluates to true so it is cleaner and has minor positive effects on load time.

If you hide the menu with javascript the menu still loads and you also add the load from the script which has minor negative effects on load time, but also, if you use jquery then you are dependent on jquery to load. If you wrap the function in $(document).ready({});, or fire the script at the bottom of the page to ensure any referenced elements are loaded, the menu will not hide until after the rest of the document and any dependencies load. This could cause the menu to show for a small amount of time depending on the size of the document, the speed of the server, and the speed of your internet connection and your browser and machine. The menu will still exist as an element in the document including text and links. To me it feels better to not have it their at all.

matttunney
Top Contributor

content type variables/tags

Thanks for that - I found you  can use the group variable

 {% if group %} do blog stuff {% endif %}
Jsum
Key Advisor

content type variables/tags

@matttunney, Ha I should have known that. Good Job! You should mark your answer as the solution to pin it to the top for others.

tjoyce
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

content type variables/tags

@matttunney - Is it viable for you to hide the menu with jQuery? Something like

$(function(){
  if($('body').hasClass('blog')){
     //set the class of your actual menu
     $('.mymenu').hide();
  }
});

tim@belch.io

0 Upvotes