include into if with nunjucks in nodejs - node.js

I working on user's system with nodejs.
I used express and nunjucks.
I trying to render a template when the user logged to the site and anoter template when the user logoff.
{% if isLoging %}
{% include "toolbar_guest.html" %}
{% else %}
{% include "toolbar_guest.html" %}
{% endif %}
but its not working...
if I try this:
{% if isLoging %}
connected
{% else %}
not connected!
{% endif %}
its work..

{% include 'toolbar_user.html' if isLogging else 'toolbar_guest.html' %}

Related

how should i put conditional statements on a node drupal 8?

I am new to drupal 8. I want something like this:
{% if node.2 %}
...............
.........
{% endif %}
what is the correct code for this? In back end I have created several nodes like node/1, node/2. I want to put a condition in node.html.twig.
how can I achieve this?
Got to twig documentation:
{% if node is not empty %}
{% for oneNode as node %}
{{ oneNode.title }}
{{ oneNode.body }}
..................
{% endfor %}
{% endif %}
Try Like this way....
{% if node.id == 2 %}
YOUR CODE..............
{% endif %}

Add template in Twig-exel bundle

Some have some example of using template in twig-exel bundle.
Here I give you an example of how I have used it but I can't make it work.
{% xlsdocument {'template': './template_advanced.xlsx'} %}
{% xlssheet %}
{% xlsrow %}
{% xlscell %}Hello2{% endxlscell %}
{% endxlsrow %}
{% xlsrow %}
{% xlscell 1 %}Bar2{% endxlscell %}
{% endxlsrow %}
{% endxlssheet %}
{% endxlsdocument %}
I have changed the address of the file but it don't load.
If I skip the code {'template': '#./template_advanced.xlsx'}, the exel is generated.
Thanks

Jekyll Styles not rendering either on localhost:4000 or my Github, anyone to advise?

I'm using trying Jekyll Bootstrap for my blog. I've been coding with Ruby and RoR for a while. I managed to host my app on Github Pages (https://mukunzichild.github.io). However as you can see, CSS styles (Bootstrap 3) are not rendering.
I've searched on google but came up with nothing. Some people have had problems with Jekyl styles with version 3, but it was not like mine.
I even cloned the Jekyll bootstrap repo, and it only fires HTML when I run it locally. I haven't changed anything in the default files.
Let me know if there is anything I'm missing here.
It's A Jekyll Bootstrap problem (see issue here).
You can resolve this by changing bugged code in your _includes/JB/setup by former code :
{% capture jbcache %}
<!--
- Dynamically set liquid variables for working with URLs/paths
-->
{% include JB/is_production %}
{% if site.JB.setup.provider == "custom" %}
{% include custom/setup %}
{% else %}
{% if is_production and site.JB.BASE_PATH and site.JB.BASE_PATH != '' %}
{% assign BASE_PATH = site.JB.BASE_PATH %}
{% assign HOME_PATH = site.JB.BASE_PATH %}
{% else %}
{% assign BASE_PATH = nil %}
{% assign HOME_PATH = "/" %}
{% endif %}
{% if site.JB.ASSET_PATH %}
{% assign ASSET_PATH = site.JB.ASSET_PATH %}
{% else %}
{% capture ASSET_PATH %}{{ BASE_PATH }}/assets/themes/{{ page.theme.name }}{% endcapture %}
{% endif %}
{% endif %}
{% endcapture %}{% assign jbcache = nil %}

Navigation link works on mobile but not on desktop

i have this website http://sds-test.nowcommu.myhostpoint.ch/de (please use the "de" at the end) and the last link of the navigation "RECHENZENTRUM" does not works on desktop but works on mobile. How can i solve it? This is the twig code:
{% extends 'partials/base.html.twig' %}
{% set show_onpage_menu = header.onpage_menu == true or header.onpage_menu is null %}
{% macro pageLinkName(text) %}{{ text|lower|replace({' ':'_'}) }}{% endmacro %}
{% block javascripts %}
{% if show_onpage_menu %}
{% do assets.add('theme://js/singlePageNav.min.js') %}
{% endif %}
{{ parent() }}
{% endblock %}
{% block bottom %}
{{ parent() }}
{% if show_onpage_menu %}
<script>
// singlePageNav initialization & configuration
$('#navbar').singlePageNav({
offset: $('#header').outerHeight(),
filter: ':not(.external)',
updateHash: true,
currentClass: 'active'
});
</script>
{% endif %}
{% endblock %}
{% block header_navigation %}
{% if show_onpage_menu %}
<ul class="navigation">
{% for module in page.collection() %}
{% set current_module = (module.active or module.activeChild) ? 'active' : '' %}
<li class="{{ current_module }}">{{ module.menu }}</li>
{% endfor %}
{% set datacenter_page = page.find('/services/datacenter') %}
<li>{{ datacenter_page.menu() }}</li>
</ul>
{% else %}
{{ parent() }}
{% endif %}
{% endblock %}
{% block content %}
{{ page.content }}
{% for module in page.collection() %}
<div id="{{ _self.pageLinkName(module.menu) }}"></div>
{{ module.content }}
{% endfor %}
{% endblock %}
The 'rechenzentrum' link is rendered correctly, and copying the link location via right click gives a correct URL that opens a seemingly correct page. So the template rendering is fine.
The link has two onclick handlers attached to it, though. Probably one of them fails and thus prevents navigation. (The JS is minified so I did not try to debug it.)

Is it possible to turn on spaceless mode only in certain situations in twig?

I want to do something like this:
{% if compress %}{% spaceless %}{% endif %}
...
{% if compress %}{% endspaceless %}{% endif %}
I'm trying to pass ['compress' => true] to the template from PHP to turn on spaceless mode. But it causes an error; template tags need to be nested properly.
Is there any technique that would let me turn spaceless on/off from PHP?
You would have to restructure your template to do something like this instead.
{% import _self as example %}
{% macro stuff(obj) %}
output stuff with {{ obj.name }}, etc...
{% endmacro %}
{% if compress %}
{% spaceless %}
{{ example.stuff(bla) }}
{% endspaceless %}
{% else %}
{{ example.stuff(bla) }}
{% endif %}
Using macros avoids you have to duplicate the content. The import statement at the top is important, so don't forget it.
page.twig:
{% block page %}
page content
{% endblock %}
index.twig:
{% extends 'page.twig' %}
{% block page %}
{% if compress %}
{% spaceless %}
{{ parent() }}
{% endspaceless %}
{% else %}
{{ parent() }}
{% endif %}
{% endblock %}

Resources