How do you show a widget content of a piece in a page's index? - apostrophe

I'm struggling with showing some content on Apsotrophe CMS.
I am using apostrophe-pieces to create a description field:
{
name: 'description',
label: 'Description',
type: 'singleton',
widgetType: 'apostrophe-rich-text',
options: {
toolbar: [ 'Bold', 'Italic', 'Link', 'Unlink' ]
}
}
I would like it to show up in the index.html view of a custom page.
However, using {{ apos.singleton(data.piece, 'description', 'apostrophe-rich-text') }} brings up an error and it's unable to render the page. It only works in show.html
In /lib/modules/basics-pages/views/index.html, my code is:
{% extends "apostrophe-pages:outerLayoutBase.html" %}
{% block content %}
<div class="basics-grid">
{% for piece in data.pieces %}
<article>
<h4>{{ piece.title }}</h4>
{% set image = apos.images.first(piece.icon) %}
{% if image %}
<img src="{{ apos.attachments.url(image, { size: 'one-sixth' }) }}" />
{% endif %}
<div class="desc">
{{ apos.singleton(data.piece, 'description', 'apostrophe-rich-text') }}
</div>
</article>
{% endfor %}
</div>
{% endblock %}
Could someone help me with the correct code to use to show the contents of the singleton widget?

As you may know I'm the lead developer of Apostrophe at P'unk Avenue.
This code:
{% for piece in data.pieces %}
Indicates you have a loop variable called piece. That's what you want.
This code:
{{ apos.singleton(data.piece, 'description', 'apostrophe-rich-text') }}
Looks for piece as a property of data and ignores your loop variable.
Remove the data. and you should be good to go.
You'll want to add:
{{ apos.singleton(piece, 'description', 'apostrophe-rich-text', { edit: false }) }}
To avoid inline editing on the index page which would be more confusing than useful.

Related

Nested navigation in eleventy

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:

How can add multiple collection in shopify liquid for loop?

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 %}

Twig checkbox is checked

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.

How to Filter all Blog.Articles by containing specific tag in Shopify?

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 %}

django_allauth socialaccount providers disappeared

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 }}

Resources