My data is creating a number of paginated posts. My front matter is as follows:
---
pagination:
data: cms
size: 1
alias: article
addAllPagesToCollections: true
layout: "_base.njk"
tags: articles
permalink: "/articles/{{ article.title | slug }}/"
eleventyComputed:
title: "{{ article.title }}"
eleventyNavigation:
key: "{{ article.title}}"
parent: "{{articles}}" //<-- how do I set the parent?
---
I would like my nav HTML structure to read
<ul>
<li>articles</li>
<ul>
<li>post-1</li>
<li>post-2</li>
</ul>
</ul>
Thanks in advance.
You can create hierarchy by using macro's.
But there's an another way: flatten that hierarchy and assign to each node a variable that describes the nesting level.
Then a similar code (as below) can be used to render that hierarchy:
{% set level = 0 %}
{% for category in collections.categoryCollection %}
{% set ulCount = (category.level - level) | abs %}
{% for i in range(0, ulCount) %}
{% if category.level > level %}
<ul>
{% else %}
</ul>
{% endif %}
{% endfor %}
<li>
<a href="{{ category.categoryUri | url | normalize | firstPage(globals.categories.category.postPageSize) }}">
{{ category.categoryName }} ( {{category.items.length}} / {{ category.allItems.length }} )
</a>
</li>
{% set level = category.level %}
{% endfor %}
{% for i in range(0, level) %}
</ul>
{% endfor %}
Hope this helps, I know it works, used them to get something like this:
I want to show products from the collections selected from theme setting.
Here is my code:
{% assign col1 = collections[settings.collection1] %}
{% assign col2 = collections[settings.collection2] %}
{% assign col = [col1, col2] %}
{% for product in col .products %}
{{ product }}
{% endfor %}
Your code should be like this
{% for i in (1..2) %}
{% capture col %}collection{i}{% endcapture %}
{% for product in collecitons.settings[col] %}
{{product}}
{% endfor %}
{% endfor %}
please how can I do something as follows with twig checkbox
<input type="checkbox" name="checkbox">
{% if checkbox is checked %}
#do_it
{% else %}
#do_that
{% endif %}
help me, please
Checkboxes return string value.
{% if node.field_mycheckbox.value == '1' %}
<p>print 1</p>
{% else %}
<p>print 0</p>
{% endif %}
The controller:
$dispo = $mezzo->getAuDisponibile ();
// table column AuDisponibile is boolean
...
...
return $this-render ('anagrafiche/automezzi.html.twig', ['dispo' => $dispo]);
The template:
{% if dispo %}
<input input type='checkbox' name="idisponibile" value="SI" checked>
{% else %}
<input input type='checkbox' name="idisponibile" value="SI">
{% endif %}
You can check if a form field is checked with in example,
{% if form.field.children.KEY.vars.checked %}
Do something here
{% endif %}
Using it inside a loop.
{% for child in form.field %}
<input type="checkbox" name="checkbox" {{ child.vars.checked == true ? "Checked" }}>
{% endfor %}
or
<input type="checkbox" name="checkbox" {{ form.field.children.KEY.vars.checked ? "Checked" }}>
KEY being the array key.
hello is there anyone shopify experts out there .
my only goal is to filter or display all articles according to their tag .
so this is what i have so far from this forum
{% assign counter = 0 %}
{% for article in blogs['lookbook'].articles %}
{% if article.tags contains 'Fox Racing' and counter < 2 %}
{% assign counter = counter | plus: 1 %}
<div class="njohn_search_otherpage">
<a href="{{ article.url }}" title="{{ article.title | escape }}">
<div>{{ article.image.src | img_url: 'medium' | img_tag: article.title }}</div>
<div>{{ article.title }}</div>
</a>
</div>
{% endif %}
{% endfor %}
the code are working but it's only four article will showed up. but in that sample tag i have already 10 articles.
The above code has a counter that limits the articles displayed, removing that counter works as expected, filtering all the articles by a tag.
{% for article in blogs['lookbook'].articles %}
{% if article.tags contains 'Fox Racing' %}
<div class="njohn_search_otherpage"> <div>{{ article.image.src | img_url: 'medium' | img_tag: article.title }}</div> <div>{{ article.title }}</div> </div>
{% endif %}
{% endfor %}
I had working social providers few weeks/months ago, but it is not working anymore. I checked docs and still do not know what am I missing. I think it stopped working after I upgraded django to 1.8 (changed template context processors in settings.py, ...) I had google, facebook and twitter working.
Here is my settings.py regarding allauth:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# insert your TEMPLATE_DIRS here
os.path.join(PROJECT_DIR, 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
# Required by allauth template tags
'django.template.context_processors.request',
#controller context processors (portfolios)
"controller.context_processors.portfolio_processor",
],
},
},
]
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
"django.contrib.auth.backends.ModelBackend",
# `allauth` specific authentication methods, such as login by e-mail
"allauth.account.auth_backends.AuthenticationBackend",
)
#allauth settings
ACCOUNT_AUTHENTICATION_METHOD = "username_email"
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 7
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USERNAME_MIN_LENGTH = 3
ACCOUNT_PASSWORD_MIN_LENGTH = 5
LOGIN_REDIRECT_URL = "/"
SOCIALACCOUNT_PROVIDERS = \
{
'facebook':
{'SCOPE': ['email', 'publish_stream'],
'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
'METHOD': 'oauth2',
'LOCALE_FUNC': lambda request: 'en_US',
'VERIFIED_EMAIL': False},
'google':
{ 'SCOPE': ['profile', 'email'],
'AUTH_PARAMS': { 'access_type': 'online' } }
}
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.humanize',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
#library folder
'lib',
#extra apps
'django_crontab',
#search
'haystack',
#apps
'stocks',
'portfolio',
'watcher',
'suggestion',
#'broker',
#allauth
'allauth',
'allauth.account',
'allauth.socialaccount',
'loginas',
#allauth providers
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.twitter',
#bootstrap
'bootstrap3',
'bootstrap3_datetime',
#admin
'django.contrib.admin.apps.SimpleAdminConfig',
#'django.contrib.admin',
#'django.contrib.admindocs',
'debug_toolbar',
)
Of cource I have set up twitter, facebook and google in social applications in admin.
In login.html I incude providers like this:
{% if socialaccount.providers %}
<div class="col-md-5 col-lg-5">
<!--
This is the raw "real" HTML that facebook recommends.
Leaving here for reference.
<div class="fb-login-button" data-max-rows="1" data-size="large" data-show-faces="false" data-auto-logout-link="false"></div>
-->
<div class="socialaccount_ballot">
<ul class="socialaccount_providers list-unstyled">
{% include "socialaccount/snippets/provider_list.html" with process="login" %}
</ul>
<div class="login-or" style="text-align: center">{% trans 'or' %}</div>
</div>
{% include "socialaccount/snippets/login_extra.html" %}
</div>
{% endif %}
And then in socialaccount/snippets/provider_list.html:
{% load socialaccount %}
{% for provider in socialaccount.providers %}
{% if provider.id == "openid" %}
{% for brand in provider.get_brands %}
<li>
<a title="{{brand.name}}"
class="socialaccount_provider {{provider.id}} {{brand.id}}"
href="{% provider_login_url provider.id openid=brand.openid_url process=process %}"
>{{brand.name}}</a>
</li>
{% endfor %}
{% endif %}
<li style="text-align: center;">
<a title="{{provider.name}}" class="socialaccount_provider {{provider.id}}"
href="{% provider_login_url provider.id process=process scope=scope auth_params=auth_params %}">{{provider.name}}</a>
</li>
{% endfor %}
when I try to print soccialaccount, it's blank/None:
{% load socialaccount %}
{{socialaccount}}
What am I missing? I am using django 1.8 and allauth=0.23.
There were changes from 0.21, so check what happens when you do
{% get_providers as socialaccount_providers %}
{{ socialaccount_providers }}